[BUG] EACCES on ~/.npmrc is reported as a root-owned cache folder
维护者通常 2 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- javascript, node.js
- 领域
- cli
调研方向
The issue points to lib/utils/error-message.js, where the cache path check is described. Read that check and reproduce the failure with the provided read-only ~/.npmrc steps. Done when the error for ~/.npmrc names the file and shows the generic permission message, while paths inside the cache still receive the cache-specific message.
由索引模型根据 Issue 内容生成。
描述
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
This is not just a request to bump a dependency for a CVE
- This is not solely a request to bump a dependency for a CVE
Current Behavior
When npm cannot write ~/.npmrc, it reports that the cache folder contains root-owned files and tells the user to run sudo chown -R on ~/.npm. The cache is fine, so the suggested command does not fix anything. The real problem is that ~/.npmrc is not writable. That happens, for example, when a dotfiles manager such as Nix Home Manager links it to a read-only file.
npm login on such a machine fails like this:
npm error code EACCES
npm error syscall open
npm error path /Users/<user>/.npmrc
npm error errno -13
npm error
npm error Your cache folder contains root-owned files, due to a bug in previous versions of npm which has since been addressed.
npm error
npm error To permanently fix this problem, please run:
npm error sudo chown -R 501:20 "/Users/<user>/.npm"
Suspected cause: lib/utils/error-message.js decides that an error is inside the cache with a plain string prefix check, er.path.startsWith(npm.config.get('cache')). With the default cache ~/.npm, the path ~/.npmrc passes that check because the string ~/.npmrc starts with ~/.npm. Any sibling path that starts with the cache path, such as ~/.npm-global, would match the same way.
Expected Behavior
npm should show the root-owned cache message only for paths inside the cache directory. For ~/.npmrc, it should show the generic permission error, which names the file that could not be written.
Steps To Reproduce
export HOME="$(mktemp -d)"
printf 'fund=true\n' > "$HOME/.npmrc"
chmod 444 "$HOME/.npmrc"
npx -y [email protected] config set fund=false
npm prints path <tmp>/.npmrc followed by the root-owned cache message and a sudo chown -R command for <tmp>/.npm. npm login hits the same message, because it also saves to the user config.
Environment
- npm: 12.2.2 (also seen on 11.19.1)
- Node.js: 24.22.2 (also seen on 26.13.0)
- OS Name: macOS 27.0
- System Model Name: Apple Silicon Mac
- npm config: default, apart from a read-only
~/.npmrc
🤖 Created with Claude Opus 5.5 in T3 Code
- 主要语言
- JavaScript
- 星标
- 10.3k
- 派生
- 5k
- 平均合并
- 4 天 11 小时
- 30 天内合并 PR
- 26
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
npm/cli 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 2 天内回复
-
[BUG] scripts/dependency-graph.js splits npm-cli-repos.txt on os.EOL, so DEPENDENCIES.md depends on the checkout's line endings可能已有人在做 @saruk-vedant 于 7 天前认领。 未关闭Bug Needs Triage Triage Requested
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 2 天内回复
-
[BUG] npm pkg delete removes the first array item for a nonexistent property可能已有人在做 @drawliin 于 42 天前认领。 未关闭cmd:delete Priority 3
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 2 天内回复
-
create node pr: Node.js 20 deprecation & `DEP0040` warnings logged可能重新可做 关联的 PR 已关闭且未合并。 未关闭Engineering Priority 1
难度 1/5 1 小时以内 新手友好度 80/100
维护者通常 2 天内回复
-
`npm audit signatures` does not report how many packages it skipped for want of registry keys可能已有人在做 @greenlincoln05 于 63 天前认领。 未关闭Priority 3
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 2 天内回复
相似的 Issue
-
docs: add SECURITY.md vulnerability reporting policy可能已有人在做 @AK-Lmn 今天认领。 未关闭
难度 1/5 1-3 小时 新手友好度 72/100
flisk-sh/linux2wasm#12 ·
维护者通常 1 天内回复
-
possible bug
难度 2/5 1-3 小时 新手友好度 84/100
Mintplex-Labs/anything-llm#7388 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 60/100
维护者通常 1 天内回复
-
v6: Minified bootstrap.min.css is missing header info可能已有人在做 @lazerg 今天认领。 未关闭bug build confirmed has-pr v6
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
[workshop-sync] workshop/side-quest-26-01-forecast-costs.md: forecast default history window is inaccurate可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭documentation
难度 1/5 1 小时以内 新手友好度 88/100
githubnext/gh-aw-workshop#6332 ·
维护者通常 1 天内回复