[BUG] npm install removes packages when workspaces are in use
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.1k
- Forks
- 4.7k
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 19
Description
Is there an existing issue for this?
- I have searched the existing issues
This issue exists in the latest npm version
- I am using the latest npm
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. Running npm 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
- Create a directory and a package.json:
{
"name": "testlink",
"private": true,
"workspaces": ["./test"]
}
- Create a directory test and add a package.json:
{
"name": "test",
"version": "1.0.0",
"devDependencies": {
"semantic-release": "^19.0.5"
}
}
- Run
npm installin the workspace parent - Run
ln -s ../node_modules node_modulesin the test directory - Run
npm installin the workspace parent - Run
npm installin the workspace parent
Environment
- npm: 8.19.2
- Node.js: 16.15.0
- OS Name: Archlinux
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the workspace setup and symlink steps described in the issue with npm 8.19.2 and Node.js 16.15.0. Trace the npm CLI workspace install behavior across repeated runs, focusing on how the symlink is handled. Done means repeated npm install commands remain idempotent and do not remove resolved packages.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100