npm / npm/cli

[BUG] `npm i` creates wrong symlinks inside workspaces

Open
#4,921 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage Release 8.x
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

When workspace packages/bar has workspace packages/foo as a dependency npm i creates invalid foo symlink inside packages/bar/node_modules folder.

Folder structure and packages/bar/package.json file:

screenshot

readlink packages/bar/node_modules/foo prints ../packages/foo.

Expected Behavior

npm i creates valid symlinks inside workspace node_modules folder.

readlink packages/bar/node_modules/foo prints ../../../packages/foo.

Steps To Reproduce

Repro is here https://github.com/iyegoroff/npm-workspaces-symlink-bug

npm i
npm start -w packages/bar

The output will be an error: sh: ./node_modules/foo/index.js: No such file or directory.
Correct output should be foo works!.

This also reproduces when running Github Actions.

Environment
  • npm: 8.10.0
  • Node.js: 17.9.0
  • OS Name: macOS 12.3.1
  • System Model Name: Mac mini

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction repository and run npm i followed by npm start -w packages/bar; inspect the packages/bar/node_modules/foo symlink with readlink. Trace the npm workspace installation path that creates this link. Done means the link resolves to ../../../packages/foo and the command prints foo works!.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.