npm / npm/cli

[BUG] `--force` doesn't work as intended when automatically removing `node_modules` symlinks

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

Nobody has claimed this yet.

Bug Priority 2 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

If I have a symlink called node_modules to a different directory, then npm will remove this symlink and create a real folder. This has been introduced in https://github.com/npm/arborist/commit/f2b0ceebfe94123f162c3652af46f9c4c473cc36 as a safety feature, but as it doesn't disable it as specified when using --force option.

Other people have similar problems too:

Expected Behavior

It should work as intended in https://github.com/npm/arborist/commit/f2b0ceebfe94123f162c3652af46f9c4c473cc36 (don't remove symlink if --force).

I really needed this thing to work, so I had to downgrade npm to an older version.

Steps To Reproduce
  1. Create an empty folder
  2. Create a second folder inside the first one
  3. Run npm init -y
  4. Run ln -s your_folder_name node_modules
  5. Run npm install --force <any package name>
  6. node_modules no longer points to your_folder_name
Environment
  • npm: v8.3.1
  • Node.js: v17.4.0
  • OS Name: MacOS Catalina
  • System Model Name: iMac
  • npm config:
; this only showed comments and registry auth token "(protected)"

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 behavior with the listed npm install --force steps, then inspect the symlink safety change in the linked npm/arborist commit. Trace the removal decision for node_modules and compare the --force option handling. Done means the node_modules symlink remains intact during the reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.