Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to install dependencies in workspace: expected workspace package to exist #7807

Open
zamotany opened this issue Jan 8, 2020 · 130 comments

Comments

@zamotany
Copy link

zamotany commented Jan 8, 2020

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

  1. git clone git@github.com:callstack/haul.git
  2. cd haul
  3. yarn 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
@sam-b-rose
Copy link

sam-b-rose commented Jan 14, 2020

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

@klaasman
Copy link

klaasman commented Jan 15, 2020

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).

@schmod
Copy link

schmod commented Jan 15, 2020

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.

@mgcrea
Copy link
Contributor

mgcrea commented Jan 27, 2020

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

@necrifede
Copy link

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: 
{
   ...
}

@raspo
Copy link

raspo commented Feb 5, 2020

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.

@wesgro
Copy link

wesgro commented Feb 10, 2020

Same experience as @raspo
Can't install packages from the command line anymore in my workspace enabled monorepo.

@nerdyman
Copy link

nerdyman commented Feb 11, 2020

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 yarn@1.19.0 add your-deps-here

@mayteio
Copy link

mayteio commented Feb 12, 2020

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"
    ]
  },
...
}

@pitops
Copy link

pitops commented Feb 17, 2020

I am also getting this regression any news?

@OzzyCzech
Copy link

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

@pitops
Copy link

pitops commented Feb 18, 2020

As a temp solution use something yvm and use version 1.18.0. Works for me

@export-mike
Copy link

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/

cheapsteak added a commit to cheapsteak/npmcharts.com that referenced this issue Feb 26, 2020
was running into issues installing dependencies yarnpkg/yarn#7807
@LasaleFamine
Copy link

I just had the same problem on a monorepo Lerna + Yarn (v1.22). Solved re-creating the yarn.lock.

@smith
Copy link

smith commented Mar 4, 2020

This looks like a duplicate of #7734.

@mhuggins
Copy link

Running into this for @storybook/api. @nerdyman's workaround appears to have worked for me in the interim.

chmanie added a commit to JoinColony/colonyNetwork that referenced this issue Mar 18, 2020
Newer versions have a workspace issue

See yarnpkg/yarn#7807
@xiaoTuiMao
Copy link

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 yarn@1.19.0 add your-deps-here

it's work for me

@americos
Copy link

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

@remorses
Copy link

remorses commented Apr 8, 2020

So the solution to this problem is downgrading yarn, yarn 2.0 will be fun

@tilgovi
Copy link

tilgovi commented Apr 8, 2020

@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.

@gsben
Copy link

gsben commented Feb 24, 2023

if your project has lerna and used it, you can use lerna to install package instead of yarn.
such as: lerna add xxx(package name) --scope=your subproject name(if exist subproject)

@gruckion
Copy link

The above suggestion of using npx works

npx yarn@1.19.1 workspace your-deps-here

The suggestion to rename the root package.json name made no difference.

The issue was introduced with Yarn 1.19.2. Using Yarn 1.19.1 works fine. Looking at what was introduced in this version here.

The part of the code that mentions expected workspace package to exist for was modified here src/package-hoister.js

This change was introduced with this PR on May 20, 2019 which was addressing the following `Dependencies not symlinked when root package depends on older version of packages from npm, reported here.

Based on the code here, it is forcing us to list the package we want in the workspace as well as the root. It escape the hoisting logic which results in the package not being placed into the child workspace.

@mattvb91
Copy link

just as an fyi for people still posting in here. This repo is abandoned by the devs and the new "yarn" is over here: https://github.com/yarnpkg/berry

we had to drop yarn completely due to no longer having an upgrade path

Not sure why this repo is not archived at this point.

@pg328
Copy link

pg328 commented Mar 1, 2023

What worked for me:

  1. Renaming package.json name field worked for me
  • I had a name that conflicted with an npm package (I'd called it "astro" and in the example above, they called it "electron")
  1. Ensure that in package.json the private field is true.

@sheetalmjkrishna
Copy link

I was able to overcome this using a similar workaround:
First:
yarn policies set-version 1.19.0
And then:
yarn add <your dependency>

@aprilmintacpineda
Copy link

aprilmintacpineda commented Apr 17, 2023

I'm getting the same error:

yarn add @total-typescript/ts-reset
yarn add v1.22.19
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning "workspace-aggregator-a7929ca9-ae57-448a-adbb-5f1081fea51c > mymonorepo > gatsby > eslint-config-react-app@6.0.0" has unmet peer dependency "babel-eslint@^10.0.0".
warning "workspace-aggregator-a7929ca9-ae57-448a-adbb-5f1081fea51c > mymonorepo > gatsby > react-server-dom-webpack@0.0.0-experimental-c8b778b7f-20220825" has incorrect peer dependency "react@0.0.0-experimental-c8b778b7f-20220825".
warning Workspaces can only be enabled in private projects.
error An unexpected error occurred: "expected workspace package to exist for \"@typescript-eslint/visitor-keys\"".
info If you think this is a bug, please open a bug report with the information provided in "/Users/aprilmintacpineda/projects/mymonorepo/apps/api/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

Any help?

EDIT 1:

I tried deleting all node_modules directories in my apps directory, then I removed the root/yarn.lock file, then I reinstalled node modules and tried running the same command again, I got the same error but this time it's with a different file: eslint

EDIT 2:

I ran yarn policies set-version 1.18.0 and then I tried installing @total-typescript/ts-reset, this time I did yarn workspace @mymonorepo/web-app add @total-typescript/ts-reset (which also previously failed), and it worked.

@andersondanilo
Copy link

Removing the yarn.lock and the node modules, and then doing an yarn install again, solved it to me

@ccpu
Copy link

ccpu commented May 3, 2023

For me removing duplicates from yarn.lock always solves the problem, here is the package i am using:
https://github.com/scinos/yarn-deduplicate

npx yarn-deduplicate yarn.lock

@zhanghengxin
Copy link

it is easy! you can use yarn@3.5.1

For monorepos, the best version of Yarn to use is 3.5.

corepack enable

corepack prepare yarn@latest --activate

@korpiq-tiketti
Copy link

We have an nx monorepo. I get error An unexpected error occurred: "expected workspace package to exist for \"@jest/types\"" for yarn add ... in many of its project subdirectories ("workspaces").

Removing the root yarn.lock file changed that to error An unexpected error occurred: "expected workspace package to exist for \"ts-jest\"". Running npx yarn-deduplicate yarn.lock did not change that.

yarn-error.log attached.

yarn-error.log

@mvanzoest
Copy link

I recently upgraded lerna to 7.4.2 and nx to 17.1.3 and started seeing this error. None of the workarounds posted helped me because the package requires yarn 1.22.21+ (The engine "yarn" is incompatible with this module. Expected version ">=1.22.21". Got "1.19.0”). The only workaround I could find was manually adding the package to the package.json and running yarn, which seemed to work for me.

@zhanghengxin
Copy link

I recently upgraded lerna to 7.4.2 and nx to 17.1.3 and started seeing this error. None of the workarounds posted helped me because the package requires yarn 1.22.21+ (The engine "yarn" is incompatible with this module. Expected version ">=1.22.21". Got "1.19.0”). The only workaround I could find was manually adding the package to the package.json and running yarn, which seemed to work for me.我最近将 lerna 升级到 7.4.2,将 nx 升级到 17.1.3,并开始看到此错误。发布的任何解决方法都没有帮助我,因为该软件包需要 yarn 1.22.21+(引擎“yarn”与此模块不兼容。预期版本“>=1.22.21”。得到“1.19.0”)。我能找到的唯一解决方法是手动将包添加到package.json并运行yarn,这似乎对我有用。

看看你的 package.json

arthur-king-excalibur added a commit to arthur-king-excalibur/npmcharts that referenced this issue Dec 28, 2023
was running into issues installing dependencies yarnpkg/yarn#7807
@aribakker
Copy link

In my case I noticed that in two of the workspaces I had a newer version of a package than in the root package.json (specifically I had @storybook/react@^7.2.1 in the workspaces and @storybook/react@6.3.4 in the root). When I changed these to all have the same version and removed the yarn.lock file it started working. I was able to identify this package by searching for the package name in the error (webpack in this case) in the yarn-error.log.

@ps-scottmurray
Copy link

Through experimentation, I suspect that this may be caused by a version conflict between your workspace dependency version and the root version though what specifically is causing it may depend on your circumstance. In one case, I was able to address duplicates in the yarn.lock. In another case, I realized that the library was redundant in the root package. In both cases, different workspaces held different versions (I'm in the process of upgrading them)

@Badlapje
Copy link

For me adding the package in package.json manually and then running yarn install worked (instead of using yarn add <packagename

@mattvb91
Copy link

just as an fyi for people still posting in here. This repo is abandoned by the devs and the new "yarn" is over here: https://github.com/yarnpkg/berry
we had to drop yarn completely due to no longer having an upgrade path

Not sure why this repo is not archived at this point.

Yearly reminder THAT THIS PROJECT IS ABANDONED

https://github.com/yarnpkg/berry

@its-dibo
Copy link

its-dibo commented Apr 12, 2024

try deleting yarn.lock and run yarn workspace <app> add <package> again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.