Cơ BảnNode.js iconNode.js

package-lock.json là gì? Tại sao nên commit file này?

package-lock.json lưu exact versions + integrity hashes (sha512) của tất cả packages kể cả transitive dependencies — đảm bảo install reproducible trên mọi máy/CI. npm install cập nhật lock file nếu package.json thay đổi; npm ci (clean install) xóa node_modules rồi install chính xác từ lock file, không bao giờ update lock — dùng trong CI/CD để đảm bảo deterministic builds.

  • Khi nào xóa và regenerate: khi lock file bị corrupt, sau major Node.js upgrade, hoặc khi muốn update tất cả dependencies lên latest compatible.
  • Integrity field: 'integrity': 'sha512-abc...' — npm verify hash sau download, phát hiện supply chain attacks (tampered packages).
  • Tương đương: yarn.lock (Yarn), pnpm-lock.yaml (pnpm) — cùng mục đích nhưng format khác nhau.
  • Quan trọng: KHÔNG commit lock file của library packages lên npm registry (chỉ commit lock của applications).

Xem toàn bộ Node.js cùng filter theo level & chủ đề con.

Mở danh sách Node.js