yarn
yarn copied to clipboard
Failed to install dependencies in workspace: expected workspace package to exist
Do you want to request a feature or report a bug? Bug
What is the current behavior?
yarn install fails with:
error An unexpected error occurred: "expected workspace package to exist for \"@babel/template\"".
The error started occurring after upgrading yarn to 1.19 and it still persists in latest stable version 1.21.1
Similar errors can be observed in #7797 and #7734
If the current behavior is a bug, please provide the steps to reproduce. The error can be reproduced when installing dependencies in https://github.com/callstack/haul
git clone [email protected]:callstack/haul.gitcd haulyarn install
What is the expected behavior?
yarn install should successfully install dependencies.
Please mention your node.js, yarn and operating system version.
- Node:
12.14.1/13(reproducible on both) - yarn:
1.21.1 - OS: macOS 10.15.2
Experiencing the same behavior when trying to add a dependency to a workspace package:
yarn workspace @scope/mypackage add npm-package
error An unexpected error occurred: "expected workspace package to exist for \"@babel/highlight\"".
Similar details
Yarn version:
1.21.1
Node version:
10.17.0
Platform:
darwin x64
OS
macOS 10.15.2
Experiencing the same issue with node@10:
An unexpected error occurred: "expected workspace package to exist for \"lru-cache\"".
Node: 10.15.3
yarn: 1.21.1
OS: macOS 10.15.1
I found a (temporary) workaround by running the policies feature of yarn in my repo:
> yarn policies set-version 1.18.0
which basically means:
Under the hood, the command will simply download the single-file release from the GitHub repository, store it inside your project (inside the .yarn/releases folder), then finally update your configuration to point to the new file (using yarn-path).
Also seeing this in Yarn 1.21.1. I can reproduce the error in my repository when running yarn upgrade-interactive, but manually bumping versions in package.json still works fine for some reason.
Encountering this as well:
error An unexpected error occurred: "expected workspace package to exist for \"string-length\"".
When trying to add an unrelated dependency inside one on my workspace packages yarn add @reduxjs/toolkit. Manually adding the dep to package.json followed by a yarn does work.
Tried yarn cache clean, and did delete both yarn.lock & node_modules folders, no change.
▶ yarn --version
1.21.1
Same error here:
$ yarn workspace @scope/web add ramda
error An unexpected error occurred: "expected workspace package to exist for \"chalk\"".
info If you think this is a bug, please open a bug report with the information provided in "/home/user/projects/web/apps/web/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
error Command failed.
Exit code: 1
Adding yarn-error.log
Arguments:
/home/user/.nvm/versions/node/v10.13.0/bin/node /home/user/.nvm/versions/node/v10.13.0/lib/node_modules/yarn/lib/cli.js add ramda
PATH:
/home/user/.yarn/bin:/home/user/.config/yarn/global/node_modules/.bin:/home/user/.yarn/bin:/home/user/.config/yarn/global/node_modules/.bin:/home/user/.nvm/versions/node/v10.13.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/user/Android/Sdk/emulator:/home/user/Android/Sdk/tools:/home/user/Android/Sdk/tools/bin:/home/user/Android/Sdk/platform-tools:/home/user/Android/Sdk/emulator:/home/user/Android/Sdk/tools:/home/user/Android/Sdk/tools/bin:/home/user/Android/Sdk/platform-tools
Yarn version:
1.21.1
Node version:
10.13.0
Platform:
linux x64
Trace:
Invariant Violation: expected workspace package to exist for "chalk"
at invariant (/home/user/.nvm/versions/node/v10.13.0/lib/node_modules/yarn/lib/cli.js:2314:15)
at _loop2 (/home/user/.nvm/versions/node/v10.13.0/lib/node_modules/yarn/lib/cli.js:94898:9)
at PackageHoister.init (/home/user/.nvm/versions/node/v10.13.0/lib/node_modules/yarn/lib/cli.js:94957:19)
at PackageLinker.getFlatHoistedTree (/home/user/.nvm/versions/node/v10.13.0/lib/node_modules/yarn/lib/cli.js:48743:20)
at PackageLinker.<anonymous> (/home/user/.nvm/versions/node/v10.13.0/lib/node_modules/yarn/lib/cli.js:48754:27)
at Generator.next (<anonymous>)
at step (/home/user/.nvm/versions/node/v10.13.0/lib/node_modules/yarn/lib/cli.js:310:30)
at /home/user/.nvm/versions/node/v10.13.0/lib/node_modules/yarn/lib/cli.js:328:14
at new Promise (<anonymous>)
at new F (/home/user/.nvm/versions/node/v10.13.0/lib/node_modules/yarn/lib/cli.js:5301:28)
npm manifest:
{
...
}
I have been experiencing the same issues since v1.19.
yarn upgrade-interactive became unusable; It would fail to apply the version updates.
After updating to v1.21 I'm not able to yarn install anymore. It always throws this error:
expected workspace package to exist for ...
Downgrading to 1.18 fixed both issues.
I should point out that these problems only occur on one project, which is a monorepo that uses lerna and yarn workspaces.
Same experience as @raspo Can't install packages from the command line anymore in my workspace enabled monorepo.
I didn't want to have to downgrade yarn since it comes from my package manager so I used npx as a terrible workaround.
npx [email protected] add your-deps-here
Also get this 1.17 through 1.22. It seems to be a handful of packages - starting with istanbul-lib-instrument. Then jest-snapshot then cssstyle repeatedly.
Invariant Violation: expected workspace package to exist for "istanbul-lib-instrument"
at invariant (/usr/local/Cellar/yarn/1.22.0/libexec/lib/cli.js:2314:15)
at _loop2 (/usr/local/Cellar/yarn/1.22.0/libexec/lib/cli.js:94959:9)
at PackageHoister.init (/usr/local/Cellar/yarn/1.22.0/libexec/lib/cli.js:95018:19)
at PackageLinker.getFlatHoistedTree (/usr/local/Cellar/yarn/1.22.0/libexec/lib/cli.js:48743:20)
at PackageLinker.<anonymous> (/usr/local/Cellar/yarn/1.22.0/libexec/lib/cli.js:48754:27)
at Generator.next (<anonymous>)
at step (/usr/local/Cellar/yarn/1.22.0/libexec/lib/cli.js:310:30)
at /usr/local/Cellar/yarn/1.22.0/libexec/lib/cli.js:328:14
at new Promise (<anonymous>)
at new F (/usr/local/Cellar/yarn/1.22.0/libexec/lib/cli.js:5301:28)
lerna.json
{
"packages": [
"packages/*",
"apps/*"
],
"version": "1.0.17",
"npmClient": "yarn",
"useWorkspaces": true
}
package.json:
{
...
"workspaces": {
"packages": [
"apps/*",
"packages/*"
],
"nohoist": [
"**/webpack-dev-server"
]
},
...
}
I am also getting this regression any news?
same here, monorepo and yarn interactive upgrade on mac
Invariant Violation: expected workspace package to exist for "stack-utils"
at invariant (/usr/local/Cellar/yarn/1.22.0/libexec/lib/cli.js:2314:15)
at _loop2 (/usr/local/Cellar/yarn/1.22.0/libexec/lib/cli.js:94959:9)
at PackageHoister.init (/usr/local/Cellar/yarn/1.22.0/libexec/lib/cli.js:95018:19)
at PackageLinker.getFlatHoistedTree (/usr/local/Cellar/yarn/1.22.0/libexec/lib/cli.js:48743:20)
at PackageLinker.<anonymous> (/usr/local/Cellar/yarn/1.22.0/libexec/lib/cli.js:48754:27)
at Generator.next (<anonymous>)
at step (/usr/local/Cellar/yarn/1.22.0/libexec/lib/cli.js:310:30)
at /usr/local/Cellar/yarn/1.22.0/libexec/lib/cli.js:328:14
at new Promise (<anonymous>)
at new F (/usr/local/Cellar/yarn/1.22.0/libexec/lib/cli.js:5301:28)
$ yarn lerna --version
3.20.2
$ yarn version
1.22.0
$ node --version
v13.8.0
As a temp solution use something yvm and use version 1.18.0. Works for me
yarn policies set-version 1.18.0 works for me - yarn will automatically switch to this version just for the project! so neat!
https://classic.yarnpkg.com/en/docs/cli/policies/
I just had the same problem on a monorepo Lerna + Yarn (v1.22). Solved re-creating the yarn.lock.
This looks like a duplicate of #7734.
Running into this for @storybook/api. @nerdyman's workaround appears to have worked for me in the interim.
I didn't want to have to downgrade yarn since it comes from my package manager so I used npx as a terrible workaround.
npx [email protected] add your-deps-here
it's work for me
I had this same problem and although deleting yarn.lock and running yarn install (or yarn workspace some-workspace bla bla bla) worked, the problem was that I was using a newer version of yarn compare to my team members.
So the solution was to use yarn policies. You basically run yarn policies set-policy and this will download the latest stable version of yarn and save it in .yarn/ and also update your .yarnrc to point to downloaded yarn version. This way you can ensure everyone is using the same yarn version and avoid this kind of isues.
More info here: https://classic.yarnpkg.com/en/docs/cli/policies#toc-policies-set-version
So the solution to this problem is downgrading yarn, yarn 2.0 will be fun
@remorses apologies if I incorrectly read sarcasm in your reply. I haven't seen anyone submit a PR to fix this in 1.x. It's possible that, in other issues, folks have submitted fixes for this or other bugs that have been rejected, and that would make me sad. If there are abundant PRs for 1.x that are being ignored, I would hope that the maintainers would welcome community members who want to help maintain 1.x. Without PRs and maintenance from the community, it's hard to fault anyone for wanting to focus on their active development branch.
This usually happens if you are using a different version of the same npm package in workspaces.
Let's say you have @scope/www and @scope/api workspaces and both are have eslint npm package. But @scope/www is using [email protected] whereas @scope/api is using [email protected]. Also, you have [email protected] in the root packages.json.
Then if you try to install a package to one of the workspaces, you will get error An unexpected error occurred: "expected workspace package to exist for \"eslint\"". error. Because none of your eslint versions are identical.
Once you make them identical then you shouldn't get any error.
That's interesting, thanks for the additional details @abdullahceylan - Just curious: How did Yarn before 1.19.2 (no error) handle this situation?
It also gives the same error to me @friederbluemle
I was experiencing this issue because I had different versions of @babel/core in my workspaces, just as @abdullahceylan said. Updating @babel/core to the same version solved the problem for me! 🙏
I wish there was a more specific message for this error.
Also had this problem but could solve it: The reason was that I had a package (eslint) in one of my packages and in the root workspace. Removed it from the root workspace and everything was working again.
Found out that my issues came from that @babel/core in nextjs was fixed on 7.7.7 and some other modules were requiring ^7.10.0 so thats why yarn puts an extra node_module folder inside your package to resolve the dependency conflicts.
I solved it use resolutions by doing
"resolutions": {
"**/@babel/core": "7.10.2"
},
And did a yarn install / npx lerna bootstrap
In the application I am working on I was able to resolve this bug by changing
"workspaces": [
"packages/**/*"
],
to
"workspaces": [
"packages/@org1/*",
"packages/@org2/*",
"packages/*"
],
Perhaps yarn is accidentally detecting a nested workspace inside the node_modules of one of my packages? I didn't have time to look into it. I was using yarn 1.22.4.
EDIT: This seems to be corroborated by the claims that consolidating dependency versions (which in turn hoists them out of the packages directory) can also solve this problem.
what worked for me is
yarn lerna add npmpackage --scope=@scope/my-package
you can use npx instead of yarn here
Same here yarn add completely blows up on trying to do any package. Please fix 🙏