Use nohoist for Yarn Workspace in Monorepo


We have some mono repos containing a couple of Lambda NodeJS packages.

/
/lambdas
/lambdas/lambdaA
/lambdas/lambdaB

As the repo is configured to use yarn workspace. When we run, yarn install by default node_modules are saved in the root directory of the repo.

{
  "private": true,
  "workspaces": {
      "packages": [
          "lambdas/*"
      ]
  },
  "packageManager": "yarn@3.2.1"
}

In our use case, we must save the node_modules in each package directory. For that, we can add nohoist it into the package.json like below.

{
  "private": true,
  "workspaces": {
      "packages": [
          "lambdas/*"
      ],
      "nohoist": [
        "**"
      ]
  },
  "packageManager": "yarn@3.2.1"
}

Leave a Reply

Your email address will not be published. Required fields are marked *