GrepBoard/Manuals
605 manuals ·

Fix npm ENOENT: Could not read package.json

·Tested on Node.js 22.23.4 · npm 10.9.9 · npm 9.9.4 · npm 11.19.1 (Docker node:*-slim) · 2026-10·Test scope ↓·7 steps

npm ENOENT Could not read package.json means the folder npm uses as the project has no package.json. Read the path line, then cd or use --prefix.

output
npm error code ENOENTnpm error syscall opennpm error path /srv/app/package.jsonnpm error errno -2npm error enoent Could not read package.json: Error: ENOENT: no such file or directory, open '/srv/app/package.json'npm error enoent This is related to npm not being able to find a file.

When npm install or npm run ends with this, the folder npm picked as the project has no package.json — almost always because the command ran in the wrong folder. Match the npm error path line to where package.json really is. npm 9 and older print the same text as npm ERR! enoent Could not read package.json (every line starts with npm ERR!). The wording was identical on npm 9.9.4, 10.9.9 and 11.19.1.

[1] Read the npm error path line. If its folder is the one you are in (pwd) and there is no package.json there, this article applies. If the path points to some other file (node_modules/…, a file a script opens), it is a different error — follow that file instead.

[2] Find where the real package.json is. Repositories that keep the app in frontend/ or web/ rather than at the root hit this often.

console
$ npm run build$ find . -maxdepth 3 -name package.json -not -path '*/node_modules/*'
output
npm error path /srv/app/package.json…./frontend/package.json

[3] Run from that folder, or name the folder with --prefix without changing directory. In scripts and CI, --prefix cannot be undone by a forgotten cd.

console
$ npm --prefix frontend run build
output
> web@1.0.0 build> echo build ok build ok

Running from a subfolder is fine. npm walks up from the current folder and uses the first folder that has a package.json or a node_modules. The next run is a separate example, not a continuation of the one above: a project with /srv/app/package.json at the root and a src/ folder below it. npm run build inside src/ still works, and npm prefix shows which folder npm chose.

console
$ cd src$ npm prefix
output
/srv/app

[4] Check the file name. Linux is case-sensitive: in a folder that only has Package.json, npm install failed with the same ENOENT. This shows up when a repo made on Windows or macOS runs in a Linux container or CI. Rename it, for example git mv Package.json package.json.

[5] Tell neighbouring errors apart. These came from the same setup:

SituationError printed
No package.json in the foldercode ENOENT · Could not read package.json
package.json is an empty filecode EJSONPARSE · Unexpected end of JSON input
npm ci with package.json but no package-lock.jsoncode EUSAGE · can only install with an existing package-lock.json
-w packages/web and that folder has no package.jsonNo workspaces found: --workspace=packages/web

A workspace counts only when its folder has its own package.json. If you created the folder but never ran npm init -w packages/web, you get the last row.

[6] If you ran npm install <package> in an empty folder, clean up what it left. A bare npm install stops with ENOENT, but with a package name npm creates a package.json right there and installs. If that lands in the wrong folder (your home folder, /srv), every folder below it uses that file as the project.

console
$ cd /srv$ npm install is-number@7.0.0$ mkdir -p /srv/proj && cd /srv/proj$ npm install is-odd@3.0.1$ npm prefix$ ls /srv/proj$ cat /srv/package.json
output
added 1 package in 842msadded 2 packages in 925ms/srv{  "dependencies": {    "is-number": "^7.0.0",    "is-odd": "^3.0.1"  }}

The install ran in /srv/proj, but /srv/proj stayed empty and the package went into the parent's package.json. If installs in a new project end up somewhere else, use npm prefix to find the stray package.json/node_modules above it, remove them, and start the project with npm init -y. Look inside that package.json first to make sure it is not another project's.

[7] In Docker, check the WORKDIR and COPY order. COPY package*.json ./ must come before RUN npm ci, and with -v bind mounts the mounted folder must be the project folder. Running ls inside the container to see package.json is the fastest check.

For permission errors during install see npm install -g EACCES; for dependency version conflicts see npm ERR! code ERESOLVE.

#npm#nodejs#enoent#package-json#workspaces