Yarn: Yarn workspace `nohoist` option does not seem to work as documentation states...

Created on 20 Sep 2018  路  8Comments  路  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?
A bug?

What is the current behavior?
Yarn workspace nohoist option does not seem to work as documentation states...

If the current behavior is a bug, please provide the steps to reproduce.

json { "workspaces": { "packages": ["A"], "nohoist": ["A/B", "A/B/**"], }, }

What is the expected behavior?

The B and all it's dependencies are available in A/node_modules

Only works as follows:

json { "workspaces": { "packages": ["A"], "nohoist": ["**/B", "**/B/**"], }, }

Please mention your node.js, yarn and operating system version.
shell $ node -v && yarn -v && lsb_release --description && uname -a v8.12.0 1.9.4 Description: Ubuntu 17.10 Linux alita 4.13.0-46-generic #51-Ubuntu SMP Tue Jun 12 12:36:29 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

See also description in https://github.com/AubreyHewes/react-static-yarn-workspaces-build-error#workaround

triaged

Most helpful comment

I just got the same issue while deploying a Serverless application in mono-repo.

For those who are still dealing with this issue:
I ended up with adding the following configuration to package.json in the child repo instead of the root:

"workspaces": {
  "nohoist": ["**"]
}

All 8 comments

I just got the same issue while deploying a Serverless application in mono-repo.

For those who are still dealing with this issue:
I ended up with adding the following configuration to package.json in the child repo instead of the root:

"workspaces": {
  "nohoist": ["**"]
}

I'm not sure if what I encountered was the same issue or not, but I was getting this error when attempting to specify nohoist in the root-level package.json of my monorepo:

The workspaces field in package.json must be an array

@preco21's workaround seems to work (thanks for that).

We have currently the same problem with the default react-native nohoist configuration:

"nohoist": [
      "**/react-native",
      "**/react-native/**"
    ]

Unfortunately one of our libs has a folder structure like "lib/react-native" and so the nohoist configuration also matches the lib subfolder. Because of the missing option of using regex or at least defining a subfolder in the nohoist configuration (like "**/node_modules/react-native/**"), the setup doesn't work. Do you have any news on this issue?

@saschak42

one of our libs has a folder structure like "lib/react-native"

If this is an __own__ lib then change the directory name? Else change the nohoist to be more specific... Would this solve the situation?

The nohoist option worked as described in the original article for us once we ran rm -rf node_modules */node_modules and yarn install after adding the nohoist. Apparently if your dep is already hoisted, yarn does not respect the option, but if you re-install from scratch it does the right thing.

Any update on this ?

@EugeneZ But this should not be the normal behaviour.
For my understanding, when I change the nohoist entries in the child package.json, then run yarn install again --> It should update the packages. I'm facing the same issues.

I got a similar problem today.

After debugging it, looks like the string used to match the glob in nohoist is based on the package name, not in the directories.

Example:

//test/e2e/package.json
{
  "name": 'e2e-tests',
  "dependencies": {
    "A": 1.0.0
  }
}
nohoist: [
   "**/A", //works
   "e2e-tests/A", //works
   "test/e2e/A", //does not work
]
Was this page helpful?
0 / 5 - 0 ratings