npm / npm/cli

[BUG] Running npm install creates junctions rather than symlinks on Windows

Open
#5,189 3 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

My package.json defines a workspace as:
"workspaces": ["projects/*"]
and when I run "npm install" on Windows it creates Junctions in the node_modules folder for each of the projects in my workspace.

The problem with this is that many tools do not know how to work properly with a Junction (probably they never did). For example, the Ant <delete> task follows the Junction and removes all referenced files. In addition, a Junction is a Windows-only abstraction and does not have a counterpart on Linux whereas both Windows and Linux now have symlinks that function the same. That makes it likely that symlinks will continue to be supported by other tools and Junctions will not. For example, the Ant <delete> task works the same with symlinks on Windows and Linux. Git for Windows works with symlinks the same as Git on Linux does.

I've searched through the npm issues and found several on this topic and understand a bit of the legacy of the decision for npm on Windows to use Junction rather than symlink. Windows didn't have a symlink and when it did, at first, required administrative priveledges. But, today on Windows, a symlink is fully supported without special priveldges and it functions the same as on Linux. So I think the time has come for npm to switch over to use symlink on Windows. I am hard-pressed to think of a use case where that would cause issues. I'm sure that all future users of npm on Windows will be grateful they did not encounter a Junction.

Expected Behavior

I expect the npm "workspaces" feature to create symlinks in the node_modules directory on Windows just as it does on Linux.

Steps To Reproduce

On Windows using npm version 8.
In package.json define the workspaces as "workspaces": ["projects/*"] and then create a projects folder with a few sub-folders.

Then run "npm install".
Look in the node_modules directory to see the projects there as Junctions.

Environment
  • npm: 8.14.0
  • Node.js: v16.16.0
  • OS Name: Windows 10 version 21H2 (OS Build 19044.1766)
  • System Model Name: Dell Precision 5540
  • npm config:
C:\workspace
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
; "builtin" config from C:\Users\steve\AppData\Roaming\npm\node_modules\npm\npmrc

prefix = "C:\\Users\\steve\\AppData\\Roaming\\npm"

; "user" config from C:\Users\steve\.npmrc

msbuild_path = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\MSBuild\\Current\\Bin\\MSBuild.exe"
python = "C:\\Python3\\python.exe"

; node bin location = C:\nodejs\node.exe
; node version = v16.16.0
; npm local prefix = C:\workspace
; npm version = 8.14.0
; cwd = C:\workspace
; HOME = C:\Users\steve
; Run `npm config ls -l` to show all defaults.

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 workspace install from package.json on Windows and inspect the npm workspace-linking path that creates entries in node_modules. Done means npm creates symlinks rather than junctions for workspace packages on Windows, while preserving the expected workspace behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.