Skip to content

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

@hdodov

Description

@hdodov

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingRelease 7.xwork is associated with a specific npm 7 releaseplatform:windowsis Windows-specific

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions