npm error code ENOENT (tested)
npm error code ENOENT means npm tried to open a file that isn't there — almost always your package.json, because you ran npm in the wrong directory or it was never created. The confusing part is that several other common npm/Node failures get lumped in with it by memory or by blog posts, but they're different error classes with different fixes. We reproduced all four on npm 11.19.0 to show exactly which is which.
1. The real ENOENT: no package.json in this directory
We ran npm install in an empty directory with no package.json at all:
$ npm install
npm error code ENOENT
npm error syscall open
npm error path /tmp/npmenoent/s1/package.json
npm error errno -2
npm error enoent Could not read package.json: Error: ENOENT: no such file or directory, open '/tmp/npmenoent/s1/package.json'
npm error enoent This is related to npm not being able to find a file.
npm error enoent
npm error A complete log of this run can be found in: /home/jacque/.npm/_logs/2026-10-03T09_13_42_716Z-debug-0.log
This is the one true npm error code ENOENT. The path line tells you exactly which file npm wanted and couldn't open — here, package.json in the current directory. We confirmed this isn't install-specific: running npm run build in the same empty directory produced the byte-for-byte identical error, because every npm command needs to read package.json first, before it even looks at what you asked it to do.
Fix
- Check you're in the right directory. Run
pwdandls package.json. The most common real-world cause iscd-ing into a parent folder, a sibling project, or a freshly cloned repo's root when the actual Node project is in a subfolder (cd my-appfirst). - If the project really has no package.json yet, create one with
npm init -ybefore installing anything. - In CI/scripts, print
pwdright before the failing npm step — a wrong working directory after a badcdor a monorepo path change is the usual culprit, not a corrupted install.
2. Lookalike #1: "Missing script" is NOT ENOENT
We made a package.json with only a build script, then ran a script name that isn't defined:
$ npm run dev
npm error Missing script: "dev"
npm error
npm error To see a list of scripts, run:
npm error npm run
npm error A complete log of this run can be found in: /home/jacque/.npm/_logs/2026-10-03T09_13_46_080Z-debug-0.log
No ENOENT, no error code line at all here — just npm error Missing script: "<name>". This fires when package.json exists and parses fine, but its scripts object has no key matching what you typed. People searching for ENOENT often mean this error instead, because both come from "running the wrong npm command."
Fix
- Run
npm runwith no script name to list every script actually defined inpackage.json. - Check for a typo (
devvsstartvsserveare the most commonly confused trio) or a missingnpm installstep that was supposed to scaffold the scripts block (e.g. a framework CLI that writespackage.jsonon first run).
3. Lookalike #2: a script's target file missing is a Node error, not an npm one
We pointed the start script at a file that doesn't exist:
// package.json
"scripts": { "start": "node ./missing-file.js" }
$ npm run start
> s3-missing-file@1.0.0 start
> node ./missing-file.js
node:internal/modules/cjs/loader:1568
throw err;
^
Error: Cannot find module '/tmp/npmenoent/s3/missing-file.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1564:15)
at wrapResolveFilename (node:internal/modules/cjs/loader:1118:27)
...
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v24.21.0
This is the one we expected to also say npm error code ENOENT before testing it — it doesn't. npm successfully found and ran the start script; the failure happens one level down, inside Node's own module resolver, and Node reports it as Error: Cannot find module with code: 'MODULE_NOT_FOUND', printed straight to the terminal with no npm error prefix at all. The exit code bubbles up through npm, but the error text and code are Node's, not npm's.
Fix
- Check the path in the script string is correct relative to the project root (where
package.jsonlives), not relative to some other working directory. - If the file is generated by a build step (e.g. a
dist/output), make sure that build actually ran and produced the file before the script executes — a skipped or failed build step silently leaves the entry file missing.
4. Lookalike #3: npm ci without a lockfile is EUSAGE, not ENOENT
We ran npm ci in a directory with a valid package.json but no package-lock.json:
$ npm ci
npm error code EUSAGE
npm error
npm error The `npm ci` command can only install with an existing package-lock.json or
npm error npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm@5 or
npm error later to generate a package-lock.json file, then try again.
npm error
npm error Clean install a project
...
npm error A complete log of this run can be found in: /home/jacque/.npm/_logs/2026-10-03T09_13_48_843Z-debug-0.log
Different code again: EUSAGE, with a usage/help dump attached. Even though the underlying problem is also "a file npm needed isn't there," npm classifies a missing lockfile under npm ci specifically as a usage error, not a filesystem ENOENT.
Fix
- Run
npm installonce (which creates/updatespackage-lock.json), commit the lockfile, then switch CI back tonpm ci. - If the lockfile should exist but doesn't, check your
.gitignore— lockfiles are sometimes ignored by mistake, especially when copying a.gitignoretemplate meant for libraries rather than apps.
5. Quick reference: which error is which
| What you ran | Real error | Fix |
|---|---|---|
| Any npm command, no package.json present | npm error code ENOENT | cd to the right folder, or npm init -y |
npm run <name>, script not defined | npm error Missing script: "<name>" | npm run to list real scripts |
| Script's target file doesn't exist | Node's Error: Cannot find module / MODULE_NOT_FOUND | fix the path, or run the build step that creates it |
npm ci, no package-lock.json | npm error code EUSAGE | npm install once, commit the lockfile |
Frequently asked questions
Does npm error code ENOENT always mean package.json is missing?
In every case we reproduced, yes: it was npm failing to open package.json in the current directory. The `path` field in the error output tells you the exact file npm tried to open, so always check that line rather than assuming.
Why does npm say ENOENT instead of a plain 'file not found' message?
ENOENT is the raw errno name for the POSIX/libuv syscall error 'no such file or directory' (errno -2 on Linux/macOS). npm surfaces the underlying Node.js filesystem error code directly instead of translating it into plain English, which is why the message references an OS-level syscall (`open`) rather than package.json by name up front.
I ran npm run start and got 'Cannot find module', is that the same bug?
No. We confirmed npm successfully found and executed the start script; the failure is Node's own module resolver reporting MODULE_NOT_FOUND after npm already handed off control. Fix the path in the script string or make sure the file is built before the script runs.
Why does npm ci fail differently than npm install when a file is missing?
We measured npm ci specifically checking for package-lock.json / npm-shrinkwrap.json as a precondition and failing with a usage error (EUSAGE) plus a help dump, rather than the lower-level filesystem ENOENT that a missing package.json produces for ordinary commands.
What's the fastest way to tell which of these four errors I actually have?
Look at the first two lines npm prints. `npm error code ENOENT` with a `path` line pointing at package.json is case 1. `npm error Missing script` is case 2. A Node stack trace with no `npm error` prefix and `code: 'MODULE_NOT_FOUND'` is case 3. `npm error code EUSAGE` is case 4.
Written with AI assistance. Measured on 2026-10-03 with Node.js v24.21.0 and npm 11.19.0 on Linux. Every error block below is verbatim terminal output we captured, not copied from docs. npm's exact wording for these errors has changed across major versions in the past; we tested only 11.19.0. curl and the headers tool are free; Node.js and npm are free and open source.