Open bradbarrow opened 3 years ago
@bradbarrow can you try to reproduce on the latest version of npm? (ie. npm i -g npm
)
I believe I'm seeing this same behavior with npm v8.9.0.
@bradbarrow Did you end up finding a workaround for this?
Update: The below might be the expected result for a peer dependency stated with an exact version (e.g. 1.1.0
instead of ^1.1.0
).
Current Behaviour:
See Steps to Reproduce for details.
When running
npm install
in the root of a project with workspaces configured, duplicate versions ofreact
are installed becausenpm
installs the version that one of my packages depends on directly AND a version ofreact
that is an optional peer dependency of one of my package's dependencies resulting in:react@16.14.0
is installed in/root/node_modules/react
react@17.0.0
is installed in/root/apps/next-js-app/node_modules/react
Running the app with
npm run dev
results in React errors from duplicate versions ofreact
Expected Behavior:
react@17
satisfies my next app's own dependency AND the peer dependency of@apollo/client
and thus only:react@17.0.0
is installed in/root/node_modules/react
Steps To Reproduce:
I've provided the following reproduction example https://github.com/bradbarrow/npm-peer-deps-workspaces Run
npm install
in the root of that repository and note the duplicate versions of react withnpm list react
OR follow the full reproduction steps below:
/root
with a workspace config"workspaces": ["apps/*"]
apps/next-js-app
directoryreact@17
to thepackage.json
of the NextJS appreact-dom@17
to thepackage.json
of the NextJS app@apollo/client@3..3.7
to thepackage.json
of the NextJS app@apollo/client@3..3.7
has an optionalpeerDependency
of"react": "^16.8.0 || ^17.0.0"
npm install
in the root of the projectEnvironment: