-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Do you want to request a feature or report a bug?
Possible bug.
What is the current behavior?
Yarn workspace seems to be counting the references from external modules to decide whether to hoist a module or not. This causes an unexpected behavior in my opinion. A minimal reproduction can be looked at this repository.
In the repo, there are 3 packages, called serviceA, serviceB, and serviceC.
- serviceA has dependency to
react@16.8.6
,react-dom@16.8.6
andreact-image-fallback@8.0.0
- serviceB and serviceC have dependency to
react@16.9.0
,react-dom@16.9.0
After running yarn install
in the project root, we end up with react@16.8.6
and react-dom@16.9.0
in the root node_modules. This mismatching version can cause problems in react apps.
What is the expected behavior?
I expected that react@16.8.6
and react-dom@16.8.6
to be installed in serviceA's node_modules, and react@16.9.0
, react-dom@16.9.0
to be hoisted to root node_modules because there are more local packages that depends on them.
Even when I run yarn why react
, yarn
itself seems to be expecting react@16.9.0
to be hoisted, not react@16.8.6
.
yarn why v1.17.3
[1/4] 🤔 Why do we have the module "react"...?
[2/4] 🚚 Initialising dependency graph...
[3/4] 🔍 Finding dependency...
[4/4] 🚡 Calculating file sizes...
=> Found "react@16.9.0"
info Has been hoisted to "react"
info Reasons this module exists
- "workspace-aggregator-0de2b996-5873-43fd-bf58-f1a0a092304c" depends on it
- Hoisted from "_project_#serviceb#react"
- Hoisted from "_project_#servicec#react"
info Disk size without dependencies: "248KB"
info Disk size with unique dependencies: "436KB"
info Disk size with transitive dependencies: "524KB"
info Number of shared dependencies: 3
=> Found "servicea#react@16.8.6"
info This module exists because "_project_#servicea" depends on it.
✨ Done in 0.13s.
Please mention your node.js, yarn and operating system version.
Node version: 10.16.2
Yarn version: 1.17.3
OS version: macOS 10.14.6