npm / npm/cli

[BUG] npm install removes linked packages, npm link replaces linked package contents

Open
#2,380 19 comments 16 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug platform:windows Release 7.x
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

I have specified a package in my package.json that I have also linked with a local version I use for development. When I run npm i in the parent package, the symlink is removed, the package is installed from npm, and I use the live version instead, not my local development one.

Later, if I run npm link, the package correctly get linked with my local version, but everything is replaced with the downloaded version, meaning that all my local development files are replaced with the contents of the tarball downloaded from npm. This means I have to go in my package folder, clone the repo again, checkout the files from the master branch... Not to mention that if I have any unsaved work, it would get completely erased with no chance to get it back even via Git - because the .git folder is also deleted.

Current Behavior:
  • running npm i removes linked packages and installs their published versions instead
  • running npm link <package> replaces the contents of the symlinked package folder with the published package's tarball contents
Expected Behavior:
  • running npm i should ignore packages in node_modules that are symlinked
  • running npm link <package> should only create a symlink and leave everything in the symlinked folder intact
Steps To Reproduce:
  1. Install a package from npm in a project
  2. Run npm link in a different, local version of the package
  3. Run npm link <package> in the project
  4. Run npm i
  5. Linked package is removed
  6. Run npm link <package> in the project
  7. Local version is replaced with the published tarball contents
Environment:
  • OS: Microsoft Windows 10 Pro, 10.0.18363 Build 18363
  • nvm: 1.1.7
  • Node: 15.4.0
  • npm: 7.0.15 (can't install 7.2 due to nvm)

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 listed npm link and npm i sequence on the stated Node 15.4.0/npm 7.0.15 environment. Trace the package-manager paths handling linked packages and compare the symlink and package contents before and after each command. Done means npm i preserves linked packages and npm link does not overwrite the local package or its .git directory.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.