New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] npm install removes packages when workspaces are in use #5598
Comments
node_modules can’t be a symlink; why do you need that step at all? |
I have a dotnet project that consumes npm packages that are restored to node_modules. When I have the project checked out as normal this isn't a problem. When I use the project as part of a workspace arrangement where I want to work on multiple projects simultaneously this only works if the dotnet build has the node_modules folder where it is expected. |
Then if it needs node_modules, it should have a package.json and npm install should be ran there. |
Which is what I'm doing. But if you use workspaces then npm install delegates itself to the directory containing the package.json that declares the workspaces. You end up with a node_modules folder there which works fine for nodejs due to how that one resolves dependencies but doesn't work for any other software that wants to consume from a local node_modules. Clarification: If you run npm install on any package.json that is part of a workspaces arrangement no local node_modules folder is created for those. |
If other software isn’t matching node’s resolution algorithm for files inside node_modules, it’s broken - file an issue there. |
This isn't helpful in the least. Its not broken, dotnet simply isn't javascript software that should have to care about node_modules or any magic way of how nodejs resolves packages. As part of the build process of our software I rely on the fact that if we distribute npm packages I can restore them to a node_modules folder local to my project. Which is the default behaviour of The fault lies with npm and the current workspace implementation not with a different software not using nodes module resolution algorithm for packages that it doesn't even natively read. |
@Blackclaws Have you tried using the It may offer better support for your use case. 🙂 |
Okay, so for whatever reason I had a symlink between a workspace's In the meantime, I went all in on Perhaps some kind of warning could be introduced when symlinked node_modules is found in a workspace? |
The fact that npm doesn't deduplicate the node_modules folder if it all references the same one is a bug to begin with imho. |
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
I'm using npm workspaces to link multiple projects together locally for development. As I am not using a pure node js development setup but there are other technologies involved I require that each project has a local node_modules that can be resolved.
I therefore create a parent package.json linking to the subfolders as workspaces. I then run
npm install
.Afterwards I symlink the node_modules directory to the workspace children.
It seems that this symlink is what breaks
npm install
.On running
npm install
a second time, dependencies get uninstalled. Runningnpm install
again reinstalls them and so and so forth.Expected Behavior
Npm installs resolved packages once and further npm install commands are idempotent.
Steps To Reproduce
npm install
in the workspace parentln -s ../node_modules node_modules
in the test directorynpm install
in the workspace parentnpm install
in the workspace parentEnvironment
The text was updated successfully, but these errors were encountered: