npm / npm/cli

[BUG] npm link removes previously linked module

Open
#4,287 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Priority 2 ws:arborist
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

What / Why

Developing coupled packages linked with npm link is not optimal.

  1. npm link breaks the linked package.
  2. npm link removes others links. (regression from npm 6)

When

Developing/testing linked packages together

Where

  • n/a

How

Current Behavior
  • n/a
Steps to Reproduce

Preparing the environment

git clone https://github.com/yeoman/environment.git
cd environment
npm ci
npm link
cd ..
git clone https://github.com/yeoman/generator.git
cd generator
npm ci
npm link
cd ..
git clone https://github.com/yeoman/yeoman-test.git
cd yeoman-test
npm ci
npm link
cd ..

Reset the environment

cd environment
npm ci
cd ..
cd generator
npm ci
cd ..
cd yeoman-test
npm ci
cd ..
  1. npm link breaks the linked package.
cd yeoman-test
npm link yeoman-generator
npm test

output:

Error: Cannot find module 'semver'
Require stack:
- /Users/mshima/git/reproduce/generator/lib/index.js
- /Users/mshima/git/reproduce/yeoman-test/test/helpers.js

Workaround go to generator folder and execute npm ci

  1. npm link removes others links. (regression from npm 6)
cd yeoman-test
npm link yeoman-generator
ls -l node_modules/yeoman-*

output:

lrwxr-xr-x  1 mshima  staff  15  6 Mar 12:14 node_modules/yeoman-generator -> ../../generator

node_modules/yeoman-environment:
total 24
drwxr-xr-x   4 mshima  staff   128  6 Mar 12:14 cli
.
.
.
npm link yeoman-environment
ls -l node_modules/yeoman-*

output:

lrwxr-xr-x  1 mshima  staff  17  6 Mar 12:20 node_modules/yeoman-environment -> ../../environment

node_modules/yeoman-generator:
total 32
-rw-r--r--   1 mshima  staff  1292 26 Out  1985 LICENSE
drwxr-xr-x   5 mshima  staff   160  6 Mar 12:20 lib
.
.
.

Workaround: link both together npm link yeoman-generator yeoman-environment

ls -l node_modules/yeoman-*
lrwxr-xr-x  1 mshima  staff  17  6 Mar 12:20 node_modules/yeoman-environment -> ../../environment
lrwxr-xr-x  1 mshima  staff  15  6 Mar 12:22 node_modules/yeoman-generator -> ../../generator
Expected Behavior
  1. should not break node_modules tree.
  2. should not remove others manually linked modules.

Who

  • n/a

References

  • n/a

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 by reproducing the two failures with the provided environment, generator, and yeoman-test clone commands, then run npm link yeoman-generator and npm link yeoman-environment followed by npm test. Compare the linked and unlinked node_modules/yeoman-* entries. Done means linked packages retain their dependencies and linking one package does not remove another manual link.

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
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.