Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

npm audit stops with ENOLOCK because there is no lockfile

Errornpm ERR! code ENOLOCK

Short answer

npm audit sends the dependency tree from your lockfile to the registry. By default it refuses to run without a package-lock.json or npm-shrinkwrap.json, which is what ENOLOCK means. Create the lockfile with npm install --package-lock-only, and check that the package-lock setting is not turned off in an .npmrc.

  • Applies to npm 10, Node.js 22, React 19
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Look for the lockfile in the folder where you ran the command. If neither file is listed, the first cause below applies.

    ls package-lock.json npm-shrinkwrap.json
  2. 2Match what you see, then jump to its fix

    1. 1ls reports 'No such file or directory' for both package-lock.json and npm-shrinkwrap.jsonThe project has no package-lock.jsonFix
    2. 2The lockfile is missing again right after you create it, or npm install never writes oneThe package-lock setting is switched off in an .npmrcFix

What does the error look like?

  • npm ERR! code ENOLOCK
  • npm ERR! audit
  • loadVirtual

Cause 1 of 2

The project has no package-lock.json

1Check

A fresh clone that only has package.json, a lockfile that was never committed, or a .gitignore entry for it all leave audit with nothing to read. Confirm you are in the project root.

pwd
git ls-files package-lock.json

2Fix

Write the lockfile without touching node_modules, then audit again. Commit the new file so teammates and CI get it too.

npm install --package-lock-only
npm audit

3Verify

The audit prints a result instead of ENOLOCK.

npm audit

Confirmed by docs.npmjs.com

Did this fix it?

Cause 2 of 2

The package-lock setting is switched off in an .npmrc

1Check

Setting package-lock to false makes npm ignore lockfiles on install and not write one. Print the value npm is using.

npm config get package-lock

2Fix

If it prints false, remove the setting (look in the project .npmrc and your user .npmrc), then create the lockfile.

npm config delete package-lock
npm install --package-lock-only

3Verify

The file now exists and audit runs.

ls package-lock.json
npm audit

Confirmed by docs.npmjs.com

Did this fix it?

How do I stop it coming back?

  • Commit package-lock.json and keep it out of .gitignore.
  • Use npm ci in CI so a missing or out-of-date lockfile fails the build early.
  • Keep one package manager per project; do not mix npm with a second lockfile.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.