yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.45k stars 2.73k forks source link

CLI functionality related to aggregator preventing yarn commands 1.19-1.22 - Reverted to 1.16 #7734

Open DavideDaniel opened 5 years ago

DavideDaniel commented 5 years ago

<!-- *Before creating an issue please make sure you are using the latest version of yarn.* --> ^ Problems started with upgrading to 1.19 and then snowballed into 5 hours of hell trying to figure out what went wrong.

Do you want to request a feature or report a bug? error An unexpected error occurred: "expected workspace package to exist for \"rimraf\"" It started with some dev dependency in a workspace repo and after messing around with nohoist settings I started noticing that the same modules keep coming up. Rimraf, inquirer, react-dev-tools.. generally things that were listed many times over in transitive dependencies. Read through many different similar issues regarding symlinks but ended up being unable to add new modules through cli which was the problem I was trying to address for automation.

What is the current behavior?

These commands do not seem to work in version v1.19.2 through v1.22.0-20191201.1637:

yarn workspace @scope/A add uuid lodash.get --dev cd packages/A && yarn add uuid lodash.get --dev yarn workspace @scope/A add js-cookie@^2.2.1 -D cd packages/A && yarn add lodash.get@^2.2.1 --dev

Tried yarn cache clear, removing node_modules, reinstalling yarn to no avail.

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

Sorry, work repos.

What is the expected behavior? Workspaces command and yarn add should work from cli.

Please mention your node.js, yarn and operating system version. Tested on the following:

Node: v8.9.4 v8.15.1 v10.11.0 v10.16.0 v10.16.2

Yarn: v1.19.2 v1.21.0 v1.22.0-20191201.1637

OS: MacOS Mojave 10.14.6

DavideDaniel commented 5 years ago

For anyone that comes looking for a quick fix.. I was able to get back to a working state by installing v16.0 https://raw.githubusercontent.com/karlhorky/homebrew-core/f8bc263f93dcfd1cc50c98976a8503c8a7cb032f/Formula/yarn.rb via homebrew. I'm gonna try seeing if the update with 1.17.4 works and go as far up as I can without losing functionality.

~I was able to go up to 1.17.4 but 1.19 and up the same issues come up.~

1.17.4 continues to have lots of symlink issues which were addressed in 1.19 but is not usable currently for me. 1.16 seems more stable but is not secure... sigh. Please let me know how I can help. Need a break and will check in later.

DavideDaniel commented 5 years ago

A clue about symlink issues while running --verbose. The uuid module keeps missing even as far back as 1.16. The common pattern right now appears to be modules that are used in many other modules but are listed as a peerDependency in a workspace can run into issues with workspace aggregator during certain cli commands. This could be because a lot of commonly used modules are listed as peerDependencies vs dependencies, following advice from https://yarnpkg.com/blog/2018/04/18/dependencies-done-right/.

DavideDaniel commented 4 years ago

From https://github.com/yarnpkg/yarn/issues/6953 image I'm wondering if 2.0 will address this with the above.. but still unsure why this became a bigger problem past 1.16. Is it because changes to 1.16 are being made with the same lens applied for code going in for 2.0? If so, should we just consider pinning our version of yarn and wait for 2.0 if we are using workspaces?

danoc commented 4 years ago

I think we're running into this issue at @thumbtack. In particular, this affects us when trying to upgrade a package within a workspace.

This snippet should reproduce the issue:

git clone git@github.com:thumbtack/thumbprint.git && cd thumbprint && yarn && cd packages/thumbprint-react && yarn upgrade @thumbtack/thumbprint-tokens --latest

This is the error you'll see:

error An unexpected error occurred: "expected workspace package to exist for \"@babel/plugin-transform-dotall-regex\"".
info If you think this is a bug, please open a bug report with the information provided in "/Users/<redacted>/thumbprint/packages/thumbprint-react/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/upgrade for documentation about this command.
danoc commented 4 years ago

Confirmed that downgrading Yarn to 1.16.0 works. Thanks for digging into this, @DavideDaniel. Saved me lots of time!

Here are downgrade instructions for those that installed with Homebrew: https://github.com/thumbtack/thumbprint/issues/592#issuecomment-565564993

troywweber7 commented 4 years ago

Downgrading worked for me. But I'd definitely like to see this fixed in the latest version of yarn so I'm not lagging behind by 5 minor versions... yikes!

iplus26 commented 4 years ago

Downgrading to v1.19.0 worked for me. Looking forward to fix this~

roni-frantchi commented 4 years ago

Downgrading to v1.19.0 worked for me. Looking forward to fix this~

Same here.

amirburbea commented 4 years ago

Any update on this?

In my lerna monorepo I have some packages (like husky and lint-staged) installed at the root

(My .yarnrc file has --ignore-workspace-root-check true)

When I try to upgrade packages (using yarn upgrade-interactive --latest) I always get Invariant Violation: expected workspace package to exist for "" where the quoted portion includes the name of the root package. Downgrading to yarn 1.17.0 has no such issue

troywweber7 commented 4 years ago

I just want to hop in and clarify my situation, in case it helps anyone else.

Failing Command

The commands that were failing for me were of the yarn workspace ${workspace} add ${package} variety.

Working Yarn Version

The indicated command is FAILING for me when using yarn=1.19.2-1 is SUCCEEDING for me when using yarn=1.19.1-1.

Install Older Yarn

First, follow the directions here: https://yarnpkg.com/lang/en/docs/install/#debian-stable

However, when it comes to the installation command, sudo apt update && sudo apt install -y --no-install-recommends yarn, you'll want to change yarn to yarn=${version}. You can find appropriate versions by doing apt-cache policy yarn.

Once you install a yarn version, you may also want to consider doing a sudo apt-mark hold yarn until this is resolved in later versions, otherwise apt upgrade will update your yarn again. You can confirm it is held by doing apt-mark showhold.

narwold commented 4 years ago

We are experiencing the same issue since updating to 1.21.1. Our message is as follows:

An unexpected error occurred: "expected workspace package to exist for \"@babel/traverse\"".

This is in a monorepo. When we downgrade to 1.19.0, the problem goes away. We don't want to do that, however, because of this recent security bulletin:

https://blog.npmjs.org/post/189618601100/binary-planting-with-the-npm-cli

Any suggestions?

StephenHaney commented 4 years ago

Also experiencing this, here's our info – happy to provide anything else that might be useful.

Basic workspace monorepo, not using lerna.

Yarn version: 1.21.1

In: yarn add ts-jest -D

Out: error An unexpected error occurred: "expected workspace package to exist for \"string-width\"".

string-width is there in my node_modules. I've tried with both string-width in the main workspace node_modules and nohoisted.

When I downgrade to 1.16.0 I can complete the install.

GeorgeTaveras1231 commented 4 years ago

My team is also experiencing this issue with version 1.21.1. However, as some other folks noted, all install commands work on prior versions (1.19.1 in our case)

This is blocking us from addressing the security issue documented here:

https://snyk.io/blog/understanding-filesystem-takeover-vulnerabilities-in-npm-javascript-package-manager/

AndreyChernykh commented 4 years ago

The same issue for our team.

yarn 1.21.1 node v10.15.1

dmfilipenko commented 4 years ago

Invariant Violation: expected workspace package to exist for "core-js-compat" yarn 1.21.1 node v13.2.0

maiertech commented 4 years ago

Same issue with yarn 1.21.1 and node v12.14.1.

IskanderMustafin commented 4 years ago

Same here.

yarn --version
1.21.1

node --version
v12.9.0
DalderupMaurice commented 4 years ago

same here

node -v && yarn -v
v10.15.3
1.21.1
aryzing commented 4 years ago

For those looking for a solution that doesn't involve changing the version of yarn you're using, editing package.json to include the version of the package you want and then running the yarn command again works just fine.

I was having a similar issue when running yarn workspace <workspace> add <pkg>, and resorted to manually amending that package's package.json and running yarn. Idea from this post.

GeorgeTaveras1231 commented 4 years ago

@aryzing thanks for that suggestion and sharing a link to that post. However, in our team with use the --frozen-lockfile flag by default (by adding it to our .yarnrc file) to avoid accidental changes to dependencies. It seems like we would need to disable that feature in order to manually edit package.json files -- and as a result, risk accidental changes to the dependencies across all workspaces, unless I'm missing something.

codyfyi commented 4 years ago

Here is a stack trace (node v12.14.0 , yarn v1.21.1):

verbose 2.685597913 Invariant Violation: expected workspace package to exist for "eslint-plugin-react"
    at invariant (/usr/local/Cellar/yarn/1.21.1/libexec/lib/cli.js:2314:15)
    at _loop2 (/usr/local/Cellar/yarn/1.21.1/libexec/lib/cli.js:94898:9)
    at PackageHoister.init (/usr/local/Cellar/yarn/1.21.1/libexec/lib/cli.js:94957:19)
    at PackageLinker.getFlatHoistedTree (/usr/local/Cellar/yarn/1.21.1/libexec/lib/cli.js:48743:20)
    at PackageLinker.<anonymous> (/usr/local/Cellar/yarn/1.21.1/libexec/lib/cli.js:48754:27)
    at Generator.next (<anonymous>)
    at step (/usr/local/Cellar/yarn/1.21.1/libexec/lib/cli.js:310:30)
    at /usr/local/Cellar/yarn/1.21.1/libexec/lib/cli.js:328:14
    at new Promise (<anonymous>)
    at new F (/usr/local/Cellar/yarn/1.21.1/libexec/lib/cli.js:5301:28)
error An unexpected error occurred: "expected workspace package to exist for \"eslint-plugin-react\"".

This appears to be a bug in the PackageHoister. See: https://github.com/yarnpkg/yarn/blob/c43f66d14b1baedc7f50055dd7c997b32be0f8b1/src/package-hoister.js#L855-L872

Meemaw commented 4 years ago

This is a serious issue as it effectively prevents any package from being installed.

Any update on when this is supposed to be fixed?

DalderupMaurice commented 4 years ago

This is a serious issue as it effectively prevents any package from being installed.

Any update on when this is supposed to be fixed?

you can manually adjust the package.json and run yarn install. The only sad part about this is that you have to sort the packages yourself from A-Z when adding new packages 😂

troywweber7 commented 4 years ago

Any update from yarn maintainers on whether this issue is even seen or recognized?

friederbluemle commented 4 years ago

Just updated to 1.22.0 via Homebrew and ran into this issue as well...

pedroSoaresll commented 4 years ago

Just updated to 1.22.0 via Homebrew and ran into this issue as well...

sorry, to me the version 1.22.0 don't solve the problem. :disappointed:

steffeli commented 4 years ago

I've run into this problem as well a couple of weeks ago. Monorepo using Lerna and yarn workspaces. All of a sudden adding packages causes An unexpected error occurred: "expected workspace package to exist for \"@typescript-eslint/eslint-plugin\"". Upgraded to 1.22.0, problem still persist.

Right now we have to manually add packages to the package.json and run yarn install.

vleandersson commented 4 years ago

Upgraded from 1.19.x to 1.22.0 and ran into this issue. yarn cache clean solved the issue for me.

jpaas commented 4 years ago

I just tried again to upgrade from 1.16.x. This time to 1.22.0. The problem still exists for me. yarn cache clean did not help.

webmaster128 commented 4 years ago

I get the same error when yarn adding something to a package of a monorepo:

error An unexpected error occurred: "expected workspace package to exist for \"@storybook/react\"".

@storybook/react is installed in the monorepo root's package.json in the devDependencies. When I change the monorepo root's devDependencies to dependencies, the issue disappears. I don't think you should do that but maybe it helps understanding and fixing the problem.

webmaster128 commented 4 years ago

For me, the problem is a regression 1.19.1->1.19.2 (as reported here). Downgrading to 1.19.1 helped.

cspotcode commented 4 years ago

Building off of https://github.com/yarnpkg/yarn/issues/7734#issuecomment-580012389

In my case, yarn erroneously thinks that a dependency is actually a child package within my monorepo workspace. In other words, I author many packages in my monorepo that all have some mix of dependencies, devDependencies, or peerDependencies on slightly different versions of ts-node. This causes yarn to incorrectly classify ts-node as being one of the monorepo's own packages. It thinks I have a ./packages/ts-node subdirectory in my monorepo, but I don't.

I think yarn is realizing it cannot hoist ts-node because there are different versions in play, so it keeps them nested within packages/*/node_modules (good) but this causes it to believe that ts-node is owned by my monorepo. (bad)

troywweber7 commented 4 years ago

Still failing for me: image (2) image (3)

AndreyChernykh commented 4 years ago

The same issue for me with yarn v1.22.4

quitedensepoint commented 4 years ago

Fails for me too on 1.22.4. Manually adding the module to package.json did work around the issue, though.

nemoDreamer commented 4 years ago

If the Yarn team have just abandoned addressing v1.x.x issues, then a deprecation notice would be nice...

san-kumar commented 4 years ago

Still facing this issue.. downgrading to 1.19.1 fixed it

sudo apt remove yarn -y
sudo npm install yarn@1.19.1 -g
friederbluemle commented 4 years ago

It is also possible to invoke a specific version of Yarn directly using npx:

npx yarn@1.19.1 upgrade-interactive

That way, is not necessary to downgrade the globally installed version. When using workspaces, it seems the last version that works is 1.19.1 (getting an error with 1.19.2).

hardchor commented 4 years ago

To downgrade to the last known working version in homebrew, run:

brew unlink yarn
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/aacaa70e8931b2b005cb8f70703b48604f4a8d2a/Formula/yarn.rb
brew switch yarn 1.19.1
apperside commented 4 years ago

Te solution provided by @friederbluemle here is the best one IMHO

danvln commented 4 years ago

Is this ever going to be fixed? I am a bit concerned about the quality of yarn in this context.

wclr commented 4 years ago

I've updated to 1.22 from older version and encountered this issue in couple of projects. But it was resolved by analysis with yarn why .... Sometimes yarn creates strange hoisting configurations when packages take in their inner node_modules a package of older versions while they could use hoisted. It is usually resolved by removing packages that hold "wrong" versions of dependencies and reinstalling them.

DavideDaniel commented 4 years ago

That moment when you google a frustrating issue, find a promising thread on github.com... only to realize deep into the comments that.. you're the original author 🤦 sigh..

I got a new work computer.. same repos, most specs are the same, OS is Catalina this time. We've been trying to pave a way forward to get to yarn 2 but it is no small feat so the fact that I ran into this again just shows that this probably deserves a patch for 1.x maintenance branch. In the meantime we are going to continue running yarn commands with @friederbluemle's suggested approach of using npx to pin the version to one where it works.

DavideDaniel commented 4 years ago

Is this ever going to be fixed? I am a bit concerned about the quality of yarn in this context.

I have a feeling effort has moved onto yarn 2 and I think someone else said it, yarn 1.x needs a deprecation notice if there is no appetite for maintaining 1.x

DalderupMaurice commented 4 years ago

Is this ever going to be fixed? I am a bit concerned about the quality of yarn in this context.

I have a feeling effort has moved onto yarn 2 and I think someone else said it, yarn 1.x needs a deprecation notice if there is no appetite for maintaining 1.x

Is this issue actually present in Yarn 2.0? If not, I'll be switching over. I'm forever stuck with an out of date yarn version atm

JasonKleban commented 4 years ago

I had success so far moving many devDependencies up to the root/solution project only and then rerunning yarn upgrade-interactive with a minimal selection of upgrades.

Side Note: I noticed along the way that sometimes it took two sequential runs of yarn (yarn install) for it to settle down and report success Already up-to-date.

ericbiewener commented 4 years ago

Thanks to all the contributors to this thread, and to @friederbluemle for the npx solution. An alternative is to issue the command yarn policies set-version 1.19.1 from inside your project. This will let you to then use the standard yarn command and have it reference that desired version only when inside your project.

rostislavbobo commented 4 years ago

It is also possible to invoke a specific version of Yarn directly using npx:

npx yarn@1.19.1 upgrade-interactive

I'm experiencing an issue with difference between yarn.locks generated with yarn v1.19.1 and latest.

You could also use lerna to add a package without downgrading the yarn version:

npx lerna add <package>[@version] --scope=<workspace>

The command above will add the package to the specified workspace package.json and update yarn.lock.

srvmux commented 4 years ago

will this ever be actually fixed?

amirburbea commented 4 years ago

Looks like no. They really want us to transition to yarn2