[BUG] `npm ci` rejects patched dependencies when the patch file is checked out with CRLF line endings (Git for Windows default)

Đang mở
#10,352 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@ultimate-kiran đang làm issue này rồi.

Từ ngày 25/11/2026.

  • #10353 của @ultimate-kiran — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript, nodejs
Lĩnh vực
cli, devtools

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Bug Needs Triage Triage Requested
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
  1. On macOS/Linux (or Windows with core.autocrlf=false): npm install <pkg>, then npm patch add <pkg>, edit a file, run npm patch commit <dir>, and commit package.json, package-lock.json and patches/.
  2. On Windows with a default Git for Windows install (git config core.autocrlf prints true): clone the repo.
  3. 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 (latest branch)
  • Node.js: 24.20.0
  • OS Name: Windows 11
  • git: Git for Windows, default core.autocrlf=true
Ngôn ngữ chính
JavaScript
Star
10.3k
Fork
5k
Merge trung bình
4 ngày 11 giờ
Pull request đã merge (30 ngày)
26

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của npm/cli

Tất cả issue của npm/cli

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.