[BUG] `npm ci` rejects patched dependencies when the patch file is checked out with CRLF line endings (Git for Windows default)
维护者通常 2 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- javascript, nodejs
调研方向
Start by reproducing with npm patch commit and npm ci on a patch file converted to CRLF, as the steps describe. The integrity check that compares the patch against patched.integrity in the lockfile is where the mismatch comes from. Linked PR #10353 is already open against this issue, so check it before starting. Done means npm ci accepts a CRLF-checked-out patch whose content matches the LF original.
由索引模型根据 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
npm patch commit writes patches/<pkg>@<version>.patch with LF line endings, and the lockfile records patched.integrity as a sha512 of the file's raw bytes.
Git for Windows sets core.autocrlf=true in its system gitconfig by default. When a teammate on Windows clones the repo, git checks the patch file out with CRLF line endings, so its hash no longer matches the lockfile and npm ci fails:
npm error `npm ci` can only install packages when your package.json and package-lock.json are in sync. Please update your lock file with `npm install` before continuing.
npm error Invalid: patch for [email protected] does not match the patch recorded in the lock file
npm install instead rewrites patched.integrity, so the lockfile keeps changing back and forth between Windows and macOS/Linux contributors.
The patch still applies correctly with CRLF line endings. Only the integrity check fails.
Expected Behavior
A patch file that differs only by git's line-ending conversion should match the recorded integrity, so npm ci installs the patched dependency.
Steps To Reproduce
- On macOS/Linux (or Windows with
core.autocrlf=false):npm install <pkg>, thennpm patch add <pkg>, edit a file, runnpm patch commit <dir>, and commitpackage.json,package-lock.jsonandpatches/. - On Windows with a default Git for Windows install (
git config core.autocrlfprintstrue): clone the repo. - Run
npm ci. It fails with the error above.
Shortcut without a second machine: after step 1, convert the patch file to CRLF, then run npm ci:
node -e "f='patches/<pkg>@<ver>.patch';fs.writeFileSync(f,fs.readFileSync(f,'utf8').replace(/\n/g,'\r\n'))"
npm ci
Environment
- npm: 12.2.3 (
latestbranch) - Node.js: 24.20.0
- OS Name: Windows 11
- git: Git for Windows, default
core.autocrlf=true
- 主要语言
- 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
-
documentation
难度 1/5 1 小时以内 新手友好度 88/100
githubnext/gh-aw-workshop#6332 ·
维护者通常 1 天内回复
-
App Designer bug
难度 2/5 1-3 小时 新手友好度 78/100
avniproject/avni-webapp#1858 ·
-
bug
难度 1/5 1 小时以内 新手友好度 96/100
hiero-ledger/hiero-sdk-js#4834 ·
维护者通常 1 天内回复
-
[组件名称] 描述问题的标题未关闭🐞 bug 🧐 unconfirmed
难度 2/5 1-3 小时 新手友好度 68/100
Tencent/tdesign-miniprogram#4744 · 1 条评论 ·
维护者通常 1 天内回复
-
Y-axis tooltip hides near the bottom of the plot while the y crosshair stays visible可能已有人在做 @lazerg 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 82/100
apexcharts/apexcharts.js#5449 ·
维护者通常 3 天内回复