Fix "expected workspace package to exist" errors #8456
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Currently, some workspace projects will produce incorrect installs or errors when commands like
yarn add
oryarn upgrade-interactive
are run from within a workspace where the workspace root the workspace have conflicting transitive dependencies.Currently, running
yarn add
from within a workspace will hoist all of that workspace's dependencies into the root'snode_modules
directory, replacing the root's own dependencies. A subsequentyarn install
eventually yields the correctnode_modules
hierarchy.Additionally, a behavior introduced in #7289 turns this scenario into a fatal error when the conflicting package is a
devDependency
.It appears that these issues occur because the package-hoister isn't considering the workspace root's dependencies when
yarn add
(or another command) is run from a directory that is not the package root. (yarn install
is a special-case that always assumes thatworkspaceRootIsCwd
totrue
)Test plan
I've been using the repo that @smably created while troubleshooting #7807 to test this patch.
Here's how I tested:
.yarnrc
and link in a locally-built Yarn executableyarn install
node_modules
from.gitignore
and stage or check-in the installed packagescd project-a
and runyarn add left-pad
– without the patch in this PR, this command will fail with an error:expected workspace package to exist for "pretty-quick"
.Another variation:
.yarnrc
and link in a locally-built Yarn executablepackage.json
andproject-a/package.json
to move alldevDependencies
todependencies
.yarn install
node_modules
from.gitignore
and stage or check-in the installed packagescd project-a
and runyarn add left-pad
– without the patch in this PR, this command will produce an incorrect node_modules hierarchy. (Runningyarn
again, however, fixes things)The current
master
branch's test-suite doesn't appear to run on my machine at all. I could use some assistance formalizing the test-scenario into a proper unit-test. (Specifically, I also couldn't figure out how to write a test for this scenario that doesn't use the live registry)Also, frustratingly, I can't figure out a more minimal reproduction scenario than the one that @smably came up with. I wish I better understood the behavior that's at the root of this bug.
Fixes #7734
Fixes #7807