Deutsch
Security wikiDependencies

What is a lockfile (package-lock.json, bun.lock)?

Also known as: package-lock.json, bun.lock, yarn.lock, pnpm-lock.yaml, dependency lock file

A lockfile records the exact version of every package your app installs. Why it matters for security in AI-built apps and how to use it correctly.

By Tim GeithnerPublished 2 min read

Short answer

A lockfile, such as package-lock.json, bun.lock, pnpm-lock.yaml or yarn.lock, records the exact version and an integrity hash of every package in your dependency tree, including the ones your packages depend on. Committed to git and used with npm ci or a frozen install, it makes every build install exactly what you tested. Without it, each install may pull in newer versions you never saw.

Ask an AI about this page:ChatGPTClaude

On this page

A lockfile is a file generated by your package manager that records the exact version of every installed package, including the packages your packages depend on, so later installs produce the same tree. npm’s docs describe package-lock.json as describing “the exact tree that was generated”. Each entry can also carry an integrity hash that is checked against the downloaded package.

package.json usually says “any 2.x version of this library” (^2.1.0). The lockfile says “exactly 2.4.3, and this is its hash”. The names differ per tool: package-lock.json for npm, bun.lock for Bun (since Bun 1.2; older projects have a binary bun.lockb), pnpm-lock.yaml and yarn.lock.

Lockfiles in an AI-built app

Lovable, Bolt and similar tools create and update the lockfile for you, which is fine as long as it is committed and actually used. Three things go wrong in practice:

  • The lockfile is missing or ignored. Then every fresh install resolves version ranges again and can pull in a release from yesterday, including a compromised one. That is how a supply chain attack on a popular package reaches apps that never asked for the new version.
  • Two lockfiles fight. A project with both package-lock.json and bun.lock gets different trees depending on who installs. Pick one package manager.
  • Lockfile changes are not reviewed. A changed lockfile can bring in a new package, or a look-alike one (typosquatting), without a visible change in package.json.

How to check your app

  • Look in the root of your repository: is there exactly one lockfile, and is it committed?
  • Check your deploy or CI command. It should be npm ci, bun install --frozen-lockfile (or bun ci) or the equivalent, not a plain install that may rewrite the lockfile.
  • When the lockfile changes in a commit, glance at which packages were added, not just updated.

How to fix or prevent it

Commit the lockfile, remove stray lockfiles of other package managers, and install with npm ci (or the frozen-lockfile option of your tool) in CI and deployments. The OWASP npm cheat sheet recommends the same: with a frozen install, “any inconsistency will abort the installation”. Update dependencies on purpose, read what changed, and run npm audit afterwards to catch packages with a known CVE.

Frequently asked questions

Should I commit package-lock.json to git?

Yes. npm’s documentation says the file is meant to be committed so that teammates, deployments and CI install the same dependency tree. Bun’s documentation says the same for bun.lock.

What is the difference between npm install and npm ci?

npm install may update the lockfile. npm ci requires a lockfile, stops with an error if it doesn’t match package.json, never writes to package.json or the lockfile, and starts from an empty node_modules. Use npm ci in CI and deployments.

Does a lockfile make my dependencies secure?

No. It makes installs repeatable, so you get what you tested and not a surprise update. If a locked version has a known vulnerability, you still need to update it on purpose.

Sources

  1. 1.package-lock.json — npm Docs
  2. 2.npm-ci — npm Docs
  3. 3.Lockfile — Bun Docs
  4. 4.NPM Security best practices — OWASP Cheat Sheet Series

Find this in your own app

ShipRely reads your repository (read-only), proves each finding with file and line, and gives you a fix prompt to paste into your AI builder.

Run a demo audit
  • Read-only access to your repository
  • Every finding with file and line
  • Fix prompts for Lovable, Cursor, Claude Code and Bolt