npm ERR! enoent Could not read package.json (ENOENT: no such file or directory): how to fix it
npm error code ENOENT with Could not read package.json means npm opened package.json in the folder it took for the project, and there was no such file. Usually npm ran in the wrong folder: the app lives in a subfolder of a monorepo, a CI step or a Dockerfile runs npm before the file is there, a stray node_modules in a parent folder misleads npm, or package.json was never committed. The path line of the error names the folder npm looked in.
By Livops team, the people who build and run LivopsUpdated
The error, as npm 10.6 and later print it (here npm ran in /app, which has no package.json):
npm error code ENOENT
npm error syscall open
npm error path /app/package.json
npm error errno -2
npm error enoent Could not read package.json: Error: ENOENT: no such file or directory, open '/app/package.json'
npm error enoent This is related to npm not being able to find a file.
npm error enoent
Older npm prints the same lines with npm ERR! in front:
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /app/package.json
npm ERR! errno -2
npm ERR! enoent Could not read package.json: Error: ENOENT: no such file or directory, open '/app/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm up to 10.5 wrote its log through npmlog, whose error level is labelled ERR![4][5]; from 10.6 npm prints the level name itself, error[6][2]. The message is the same. This page explains how npm decides where to look, lists the causes from the most common, gives the fix for each, and shows where to set the app’s folder when it is deployed on Livops.
What does the error mean?
Before most commands, npm decides which folder is the project. Starting at the current folder, it walks up the tree looking for a folder that has a package.json file or a node_modules folder, and treats the first one it finds as the current directory; if it finds none, it uses the current folder[7][8]. Then it opens package.json there. When that read fails, npm adds Could not read package.json: in front of the system’s error[3], and for ENOENT it prints the code, syscall, path and errno lines and the hint that npm could not find a file[1].
Read the path line first. It is the exact file npm tried to open. Compare it with where your package.json really is:
- The path is your current folder: npm ran in a folder without
package.json(causes 1, 2, 4, 5). - The path is a folder above your project: a parent folder has a
node_modulesfolder and npm stopped there (cause 3). - The path is inside a container, such as
/app/package.json: the file was not copied there before npm ran (cause 6).
npm uses the error’s errno as its exit code[1]. In our run of npm 11 on macOS that was 254, so a CI log may only say exited with code 254. The real cause is in the lines above it.
Causes, most common first
1. npm ran in the wrong folder
The simplest case: a terminal opened in your home folder, a cd with a typo, or a script that runs from somewhere else. Check where you are and whether the file is there:
pwd
ls package.json
npm prefix # the folder npm will treat as the project
npm prefix prints the closest parent folder that contains a package.json file or a node_modules folder[9]. Fix: cd into the folder that holds package.json, or pass it to npm. On the command line, --prefix makes non-global commands run in the folder you name[8]:
npm --prefix ./my-app install
2. The app is in a subfolder of a monorepo
The repository root has no package.json; each app has its own:
repo/
├── apps/
│ ├── web/
│ │ └── package.json
│ └── api/
│ └── package.json
└── README.md
npm install at the root fails with path /repo/package.json. Fix: run npm in the app’s folder:
cd apps/web && npm ci && npm run build
# or, without changing folder
npm --prefix apps/web ci
npm --prefix apps/web run build
If the root does have a package.json that declares the apps as workspaces, you can run a script inside one of them from the root with --workspace, and cd into the folder works as well[10]:
npm run build --workspace=apps/web
In GitHub Actions, point the steps at the app’s folder: set working-directory on a step, or defaults.run.working-directory for every run step of a job or the whole workflow[11]:
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: apps/web
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run build
3. A node_modules folder in a parent directory
Because npm stops at the first folder with a package.json or a node_modules folder[7], a stray node_modules above your project changes where npm looks. A common one is ~/node_modules, left behind by an npm install run in the home folder. npm then treats your home folder as the project, and the error’s path is ~/package.json, not your project’s.
Fix: if the parent folder is not a project, delete its stray node_modules. If your project folder simply has no package.json yet, create one there (npm init -y) so npm stops at your folder.
4. package.json is not in the repository
Your machine has the file; the clone in CI or on the server does not, because it was never added or .gitignore drops it. Check both:
git ls-files package.json # prints nothing if the file is not committed
git check-ignore -v package.json # prints the .gitignore rule that excludes it
git check-ignore -v prints the matching exclude pattern together with the path[12]. Fix: remove the rule, then commit the file with its lockfile:
git add package.json package-lock.json
git commit -m "Add package.json"
5. The file name has the wrong case
npm opens package.json, in lower case. A file named Package.json or package.JSON is found on macOS and Windows, whose file systems usually ignore case, and is missing on Linux, where CI and servers run. Rename it through Git so the rename is committed:
git mv Package.json package.json
6. A Dockerfile runs npm before package.json is copied
WORKDIR sets the folder for every RUN, CMD, ENTRYPOINT, COPY and ADD that follows it, and a COPY destination that does not start with / is relative to that folder[13]. So npm fails with path /app/package.json when it runs in /app before anything was copied there, or when the files were copied somewhere else:
FROM node:22
WORKDIR /app
RUN npm ci # fails: nothing has been copied into /app yet
COPY . .
Copy the manifest first, then install, then copy the rest:
FROM node:22
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
CMD ["npm", "start"]
Two more places to look. COPY sources are relative to the build context[13], so when you build from a monorepo root, copy from the app’s folder (COPY apps/web/package.json apps/web/package-lock.json ./). And a .dockerignore file excludes files from the build context[14]: if it lists package.json or a pattern that matches it, the file never reaches the builder.
How to confirm the fix
Reproduce what the server does: a fresh clone, then npm in the folder the server uses.
git clone <your repo> /tmp/check && cd /tmp/check/apps/web
npm prefix # must print this folder
npm ci
npm run build
If npm prefix prints this folder and npm ci gets past reading package.json, the ENOENT is fixed. A missing lockfile is a different error: npm ci says it can only install with an existing package-lock.json.
On Livops
- Tell Livops which folder holds the app. When you create a project from a GitHub repository that is a monorepo, specify the folder the project lives in, for example
apps/web. In the cabinet the field is Project folder (the docs call it the Root folder); empty means the top level, and for a repository a Browse button lets you pick the folder instead of typing it. When the form fills the field itself, it says We found the project in this folder. The same field is in the project’s settings, if the first choice was wrong. See Ways to deploy. - livops.json goes in the repository root or the project folder. Every field is optional, and what you leave out comes from the detected value; the install, build and start commands are also in Settings → Install, Settings → Build and Settings → Start. See Frameworks and livops.json.
- If your app comes up as a static site. Livops reads the code to detect the framework, and if nothing is detected, it serves the folder as a static site. If a Node app deploys as a static site, check that the project folder is the one that holds its
package.json. - A Dockerfile is used when there is one. If the repository has a
Dockerfile, Livops builds with it, so cause 6 applies to your deploy too. - Where the error shows. If the install fails, the deploy stops as
install_failed; if the build command fails, asbuild_failed. The npm error itself is in the build log. See Install failed and Build failed. - The assistant can fix the folder. It can change the project folder, and the build and start commands, for you. With auto mode on, fixing the project folder is one of the small actions it applies without waiting for your click. See Assistant.
A static site is free; an app costs 39 credits a month (39,000 so’m); see Pricing.
A build that ends with npm error code 1 has its real error above that line: see npm error code 1. If npm finds package.json but the app then fails with Cannot find module, see Cannot find module.
Questions
Which folder did npm look in?
The one in the path line of the error: the path is that folder plus /package.json. npm starts at the current folder and walks up to the nearest folder with a package.json or a node_modules folder, and uses the current folder if it finds neither. Run npm prefix to print the folder npm will use.
Is npm error the same as npm ERR!?
Yes, the same message from different npm versions. npm up to 10.5 printed its errors with npm ERR!, and npm 10.6 and later print npm error. The code, path and enoent lines are the same.
My app is in a subfolder. Do I have to cd into it?
Either cd into the folder that holds package.json, or tell npm where it is with --prefix, for example npm --prefix apps/web run build. If the repository root has its own package.json with workspaces, npm run build --workspace=apps/web runs the script inside that workspace.
Why does the error name a folder above my project?
npm walks up from the current folder and stops at the first folder that has a package.json or a node_modules folder. A stray node_modules in a parent folder, for example in your home folder, makes npm treat that parent as the project, and it has no package.json.
It works on my machine. Why does CI or the server fail?
The server has only what is in the repository. A package.json that .gitignore drops, or one that was never added, exists only on your machine. A file named Package.json also works on macOS and Windows, where file names usually ignore case, and fails on Linux.
Should I run npm init to make the error go away?
Only if this folder really is a new project. npm init creates an empty package.json without your dependencies or scripts, so the next command fails differently. If the app has a package.json somewhere else, run npm in that folder instead.
Sources
- npm CLI source — lib/utils/error-message.js (raw.githubusercontent.com). Checked .
- npm CLI source — lib/utils/display.js (raw.githubusercontent.com). Checked .
- @npmcli/package-json source — lib/read-package.js (raw.githubusercontent.com). Checked .
- npm CLI v10.5.0 source — lib/utils/display.js (raw.githubusercontent.com). Checked .
- npmlog source — lib/log.js (raw.githubusercontent.com). Checked .
- npm CLI v10.6.0 source — lib/utils/display.js (raw.githubusercontent.com). Checked .
- npm Docs — folders (docs.npmjs.com). Checked .
- npm Docs — config (prefix) (docs.npmjs.com). Checked .
- npm Docs — npm prefix (docs.npmjs.com). Checked .
- npm Docs — workspaces (docs.npmjs.com). Checked .
- GitHub Docs — Workflow syntax for GitHub Actions (docs.github.com). Checked .
- Git — git-check-ignore documentation (git-scm.com). Checked .
- Docker Docs — Dockerfile reference (WORKDIR, COPY) (docs.docker.com). Checked .
- Docker Docs — Build context (docs.docker.com). Checked .
Put your project online today
Connect GitHub or drop a folder. No card is asked for.
Deploy your Node appRelated
- Error: Cannot find module (MODULE_NOT_FOUND) in Node.js: how to fix itError: Cannot find module 'x' with code MODULE_NOT_FOUND, or ERR_MODULE_NOT_FOUND with import, means Node.js looked for a package or file and it was not there. On a server the usual causes are a package missing from package.json, a devDependency the install skipped, a path whose case differs from the file, a start command pointing at a file that was never built, or an ES module import without its .js extension.
- npm failed with return code 1 (npm ERR! code 1): how to fix the buildnpm failed with return code 1, or npm install exited with 1, is npm ERR! code 1 in newer npm: it only says that a script npm ran exited with code 1. The real error is printed above it: usually a compile or type error, a lockfile out of sync with package.json, or a dependency whose install script failed. Find the first error line above code 1, fix that, and the build passes.
- npm ci can only install packages when your package.json and package-lock.json are in sync: how to fix itnpm ci can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync (npm error code EUSAGE) means the committed lockfile no longer matches package.json: a dependency was added or changed without re-running npm install, or the lockfile was not committed. Run npm install locally, commit package.json and package-lock.json together, and npm ci passes.
- npm ERR! code ERESOLVE unable to resolve dependency tree: how to fix itnpm ERR! code ERESOLVE, unable to resolve dependency tree (npm error ERESOLVE in newer npm) means two packages in your project need versions of a shared peer dependency that cannot both be met. Since npm 7 installs peer dependencies, it stops instead of guessing. The real fix is to make the versions match: upgrade the package that is behind, or use the version it supports. --legacy-peer-deps and --force only skip the check.
- exec format error in Docker: the image was built for another CPUThe kernel refused to run the container's program because it is not an executable for this machine: almost always a binary or image built for arm64 (an Apple Silicon Mac) running on an amd64 server, or the reverse. Build for the server's platform with --platform linux/amd64, or as a multi-platform image; if the file is a script, give it a #! line.
- Node.js hosting in 2026: how to deploy an Express appA Node.js server in production needs one long-running process that listens on the port it is given, restarts when it crashes and exits cleanly on SIGTERM. On Livops you push a repository with package.json and it runs as a web app for 39 credits a month (39,000 so'm). Here is what Node needs, and how a VPS, Render, Railway, Fly.io, DigitalOcean and Heroku compare.
- Docker hosting: how to deploy a Docker container or a DockerfileTo host a container you need a host that builds or pulls the image, starts its CMD, sends traffic to the port it listens on and stops it with SIGTERM. On Livops a Dockerfile at the root of the repository is built on Livops's servers and runs for 39 credits a month (39,000 so'm); a public image from Docker Hub, GHCR or Quay runs without a build. Here is what a container needs, and how a VPS, Render, Railway, Fly.io, DigitalOcean and Heroku compare.