npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.46k stars 3.15k forks source link

[BUG] dependency installed twice when using workspace #3477

Closed nsams closed 2 years ago

nsams commented 3 years ago

Is there an existing issue for this?

Current Behavior

See this demo repository: https://github.com/nsams/npm-workspace-issue

when running npm install @mdx-js/react package is installed twice:

./packages/admin-stories/node_modules/@storybook/addon-docs/node_modules/@mdx-js/react
./node_modules/@mdx-js/react

Expected Behavior

dependency should be installed only once

Steps To Reproduce

git clone https://github.com/nsams/npm-workspace-issue
cd npm-workspace-issue
npm install
find | grep @mdx-js/react

Environment

ljharb commented 3 years ago

One of them is a symlink to the other one, no?

nsams commented 3 years ago

That's not the case:

sams@sams:~/www/npm-workspace-issue master$ ls -l ./packages/admin-stories/node_modules/@storybook/addon-docs/node_modules/@mdx-js
total 4
drwxr-xr-x 3 sams sams 4096 Jun 28 16:54 react
sams@sams:~/www/npm-workspace-issue master$ ls -l node_modules/@mdx-js/
total 16
drwxr-xr-x 2 sams sams 4096 Jun 28 16:54 loader
drwxr-xr-x 3 sams sams 4096 Jun 28 16:54 mdx
drwxr-xr-x 3 sams sams 4096 Jun 28 16:54 react
drwxr-xr-x 2 sams sams 4096 Jun 28 16:54 util
simllll commented 3 years ago

I have somehting similar, not sure if related, but it seems suddenly packages that have been hoisted before, are not correclty hoisted anymore.. but only some of them, I can't figure out why it's not working for them. e.g. i have in my package.json: "eslint-plugin-vue": "^7.12.1", "eslint-plugin-vue-scoped-css": "^1.2.1",

the first one is hoisted correcly, the 2nd is just installed within the folder of the package, and not hoisted?

ruyadorno commented 2 years ago

hi @nsams thank you for taking the time to report this issue.

I can't reproduce the problem using the linked repo but I suspect that at the time of reporting this issue there might have been conflicting versions of @mdx-js/react within your install tree which in turn would cause it to be duplicated by nesting it within the node_modules folder of a workspace.

Feel free to open a new issue in case you believe this wasn't the case and you can still reproduce the problem. Thanks again!