Agent Wranglers

STK-12Default Open source

Use npm with a lock file for JavaScript packages

Use the npm that ships with your Node.js line, commit package-lock.json, and install with npm ci in builds.

Review by

2027-04-30

How to do it

npm passes all five tests. It ships inside every Node.js release, and the registry lists npm releases from 2013. Version 12.2.0 shipped in September 2026, but Node.js 24 and 26 still bundle npm 11. In the Stack Overflow Developer Survey 2026, 54.6% of developers used it. It uses the Artistic-2.0 licence, which the OSI approves. The lock file makes every install pick the same versions, as Lock and audit dependencies requires. Block install scripts, since hijacked packages run their attack from them. A package that needs its script, such as a native module, then runs it by name with npm rebuild <name> --ignore-scripts=false. npm 12 blocks dependency install scripts by default. Approve the ones you need with npm approve-scripts <name>. Give private packages a scope mapped to your own registry, as fetch private packages only from your own registry says. The min-release-age setting, added in npm 11.10, skips versions younger than the number of days you set. Choose something else when a repository holds many packages or installs are slow, where pnpm is the pick. pnpm 1.0 shipped in June 2017, 12.14.0 shipped in October 2026, and it is MIT licensed.

Examples

Shell example

npm config set ignore-scripts true --location=project
npm config set min-release-age 7 --location=project
npm install --save-exact zod
npm ci
npm audit --audit-level=high

YAML example

steps:
  - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
    with:
      node-version: 24
      cache: npm
  - run: npm ci
  - run: npm test

How to check

package-lock.json is committed. Every build runs npm ci, never npm install. The repository has no yarn.lock or second lock file. The project .npmrc sets ignore-scripts=true and a min-release-age in days that matches Wait a few days before taking new releases.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/stack/languages-and-runtimes/npm">Agent Wranglers software choices playbook</a>. In code you write, add a comment next to it with the same link.