npm audit stops with ENOLOCK because there is no lockfile
npm ERR! code ENOLOCKShort 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.
Fix it fast
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.json2Match what you see, then jump to its fix
What does the error look like?
npm ERR! code ENOLOCKnpm ERR! auditloadVirtual
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.json2Fix
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 audit3Verify
The audit prints a result instead of ENOLOCK.
npm auditConfirmed by docs.npmjs.com
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-lock2Fix
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-only3Verify
The file now exists and audit runs.
ls package-lock.json
npm auditConfirmed by docs.npmjs.com
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Back end
Axios call from a React app comes back 404
404 (Not Found)
Status code 404 means a server answered, but it has nothing at that path.
3 causes, each with a fixBack end
npm start stops with Could not find a required file in a React app
Name: index.html
react-scripts checks for two files before the dev server starts: public/index.html and a src/index file.
3 causes, each with a fixBack end
Create React App says Node is too old, and npm will not run on the new one
npm does not support Node.js v10.19.0
The shell is running an old Node.js that is below the version Create React App needs.
3 causes, each with a fixBack end
npm says an override conflicts with a direct dependency
Override for react-error-overlay@^6.0.9 conflicts with direct dependency
npm refuses an override for a package you also depend on directly, unless both specs are exactly the same.
2 causes, each with a fixBack end
npm run build says react-scripts: Permission denied in CI
sh: react-scripts: Permission denied
The shell found node_modules/.bin/react-scripts but may not run it.
3 causes, each with a fixBack end
Babel cannot find @babel/plugin-proposal-private-property-in-object in a React app
Cannot find module '@babel/plugin-proposal-private-property-in-object'
babel-preset-react-app loads this Babel plugin but your project never lists it, so it only works while something else happens to install it.
2 causes, each with a fix