Skip to content

[BUG] npm --workspace=<ws> link <path> doesn't setup symlink in workspace #9115

@baptistedonaux

Description

@baptistedonaux

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

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

  1. 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
  2. cd npm-cli-workspaces-issue && npm ci
  3. 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
  4. npm --workspace=workspaces/foo link /tmp/lodash
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingPriority 2secondary priority issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions