[BUG] npm arborist realpath.js with UNC paths
Nobody has claimed this yet.
- 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
Try to install something on global npm install -g [package] an error is thrown:
37 verbose stack RangeError: Maximum call stack size exceeded
37 verbose stack at isPathSeparator (node:path:52:25)
37 verbose stack at resolve (node:path:217:13)
37 verbose stack at realpathCached (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\realpath.js:18:10)
37 verbose stack at realpathCached (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\realpath.js:38:10)
I added some logging to realpath.js to see what it was doing...
console.log(depth, dir, path, dir == path, base);
undefined \\SOURCE2\Users\danF\AppData\Roaming \\SOURCE2\Users\danF\AppData\Roaming\npm false npm
NaN \\SOURCE2\Users\danF\AppData \\SOURCE2\Users\danF\AppData\Roaming false Roaming
NaN \\SOURCE2\Users\danF \\SOURCE2\Users\danF\AppData false AppData
NaN \\SOURCE2\Users\ \\SOURCE2\Users\danF false danF
NaN \\SOURCE2\Users\ \\SOURCE2\Users\ true Users
NaN \\SOURCE2\Users\ \\SOURCE2\Users\ true Users
NaN \\SOURCE2\Users\ \\SOURCE2\Users\ true Users
NaN \\SOURCE2\Users\ \\SOURCE2\Users\ true Users
NaN \\SOURCE2\Users\ \\SOURCE2\Users\ true Users
...repeats until stack overflow or whatever
Expected Behavior
Expected bahavior...it works? i guess.
Given this the repeating directory error, I changed line 33 from:
if (!base) {
rpcache.set(dir, dir)
return Promise.resolve(dir)
}
to
if (!base || dir == path) {
rpcache.set(dir, dir)
return Promise.resolve(dir)
}
so that it recognizes that it has ascended as far as it can and reached the effective 'base'.
I'm no node.js/npm master, so i don't claim that this is a good fix but, i can install things globally now.
Steps To Reproduce
Windows 11. local Domain joined to Windows server, using folder redirection.
I'm not sure what other information to provide here. In this environment, all you have to do is try to install something globally and it fails.
Environment
- npm: 10.5.0
- Node.js: 20.11.1
- OS Name: Windows 11
- System Model Name: Dell generic desktop
- npm config:
; "builtin" config from \\SOURCE2\Users\danF\AppData\Roaming\npm\node_modules\npm\npmrc
prefix = "\\\\SOURCE2\\Users\\danF\\AppData\\Roaming\\npm"
; "user" config from C:\Users\danF.LEE\.npmrc
loglevel = "verbose"
; node bin location = C:\Program Files\nodejs\node.exe
; node version = v20.11.1
; npm local prefix = C:\Users\danF.LEE
; npm version = 10.5.0
; cwd = C:\Users\danF.LEE
; HOME = C:\Users\danF.LEE
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in node_modules/@npmcli/arborist/lib/realpath.js and trace the realpathCached recursion shown in the Windows UNC-path stack trace. Reproduce a global install with the provided Windows 11 folder-redirection environment, then verify that traversal stops at the effective base directory and the install completes without a stack overflow.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100