Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
My project contains two workspaces that import the same dependency in the same version.
After running the npm ci command, the top-level node_modules directory contains this dependency. The node_modules directories in each workspace do not contain this dependency, which is the expected behavior.
.
├── workspaces
│ ├── workspace1
│ │ ├── node_modules
│ │ └── package.json
│ └── workspace2
│ ├── node_modules
│ └── package.json
├── node_modules
│ └── <dependency>
│ └── package.json
└── package.json
When I want to use the local version of a dependency in a single workspace, I run the command npm --workspace=<ws> link <path>. Once the command has been successfully executed, a symbolic link is created in the top-level node_modules directory, and workspaces that have declared this dependency will have the version of the dependency specified in the package.json file (published version) in their node_modules directory.
.
├── workspaces
│ ├── workspace1
│ │ ├── node_modules
│ | │ └── <dependency>
│ │ | └── package.json
│ │ └── package.json
│ └── workspace2
│ ├── node_modules
│ │ └── <dependency>
│ | └── package.json
│ └── package.json
├── node_modules
│ └── <dependency> -> /path/to/dependency
└── package.json
Expected Behavior
When I use workspaces, I would like the npm link command to create a symbolic link in the target workspace(s).
For example, for the command npm --workspace=workspaces/workspace1 link /path/to/dependency, I expect that:
.
├── workspaces
│ ├── workspace1
│ │ ├── node_modules
│ | │ └── <dependency> -> /path/to/dependency
│ │ └── package.json
│ └── workspace2
│ ├── node_modules
│ └── package.json
├── node_modules
│ └── <dependency>
│ └── package.json
└── package.json
In this configuration, workspace1 is built using the local version of , whereas workspace2 uses the published version.
Steps To Reproduce
- Clone the repository to get a working example. The repository is hosted on my account: https://github.com/baptistedonaux/npm-cli-workspaces-issue
git clone git@github.com:baptistedonaux/npm-cli-workspaces-issue.git
cd npm-cli-workspaces-issue && npm ci
- Set up a local dependency to link it. You can use lodash as specified in the package.json.
git clone git@github.com:lodash/lodash.git /tmp/lodash
npm --workspace=workspaces/foo link /tmp/lodash
- To view the configuration of node_modules and dependencies, you can run this command:
ls -l node_modules workspaces/foo/node_modules workspaces/bar/node_modules
Environment
- npm: 11.9.0
- Node.js: v24.14.0
- OS Name:
node:24-alpine Docker image hosted on Fedora 43
- System Model Name: Linux
- npm config:
; node bin location = /usr/local/bin/node
; node version = v24.14.0
; npm local prefix = /
; npm version = 11.9.0
; cwd = /
; HOME = /home/node
; Run `npm config ls -l` to show all defaults.
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
My project contains two workspaces that import the same dependency in the same version.
After running the
npm cicommand, the top-levelnode_modulesdirectory contains this dependency. Thenode_modulesdirectories in each workspace do not contain this dependency, which is the expected behavior.When I want to use the local version of a dependency in a single workspace, I run the command
npm --workspace=<ws> link <path>. Once the command has been successfully executed, a symbolic link is created in the top-levelnode_modulesdirectory, and workspaces that have declared this dependency will have the version of the dependency specified in thepackage.jsonfile (published version) in theirnode_modulesdirectory.Expected Behavior
When I use workspaces, I would like the
npm linkcommand to create a symbolic link in the target workspace(s).For example, for the command
npm --workspace=workspaces/workspace1 link /path/to/dependency, I expect that:In this configuration,
workspace1is built using the local version of , whereasworkspace2uses the published version.Steps To Reproduce
git clone git@github.com:baptistedonaux/npm-cli-workspaces-issue.gitcd npm-cli-workspaces-issue && npm cigit clone git@github.com:lodash/lodash.git /tmp/lodashnpm --workspace=workspaces/foo link /tmp/lodashls -l node_modules workspaces/foo/node_modules workspaces/bar/node_modulesEnvironment
node:24-alpineDocker image hosted on Fedora 43