How to fix npm ERR! Error: ENOENT: no such file or directory, stat 'node_modules' in npm

npmBEGINNERMEDIUMUpdated Dec 2, 2025· 166 views

npm looked for node_modules but it does not exist yet (fresh checkout, cleaned workspace, or wrong working directory). Install dependencies or point npm at the correct folder.

Quick fix

Fixes npm ERR! Error: ENOENT: no such file or directory, stat 'node_modules'

pwd
ls node_modules 2>/dev/null
  1. Confirm the working directory
  2. Install dependencies
  3. Handle Docker/CI mounts
  4. For monorepos, run in the package directory
npm — error
pwd
ls node_modules 2>/dev/null
npm ERR! Error: ENOENT: no such file or directory, stat 'node_modules'

What this error means

npm expects node_modules to exist after installs and when resolving binaries. If you run scripts before installing dependencies, mount an empty volume over the project, or execute in the wrong directory, stat on node_modules fails with ENOENT. CI pipelines that clean workspaces, Docker bind mounts that shadow the folder, and monorepos with nested packages commonly see this when running npm run before npm install.

Typical symptoms

  • npm start/test fails with ENOENT stat 'node_modules'
  • Fresh clone without npm install yet
  • Docker container mounts an empty host directory over /app/node_modules
  • CI job cleans workspace between steps
  • Running in the wrong package folder inside a monorepo

Common causes

  1. Dependencies not installed yet (npm install/ci not run)
  2. Volume mount or cache cleared node_modules
  3. Misconfigured workdir in CI/Docker
  4. Monorepo path confusion; running at root instead of package
  5. npm cache/node_modules removed by cleanup script

How to fix "npm ERR! Error: ENOENT: no such file or directory, stat 'node_modules'"

1Confirm the working directory
bash
pwd
ls node_modules 2>/dev/null
2Install dependencies
bash
npm ci
# or
npm install
3Handle Docker/CI mounts

Ensure your container workdir matches the project root and that you are not mounting an empty host folder over node_modules.

4For monorepos, run in the package directory

If using workspaces, run npm inside the specific package that owns node_modules or enable workspaces at the root.

5Re-run the command
bash
npm run <script>

Advanced notes

CI best practice is npm ci after checkout and before running scripts; cache node_modules cautiously to avoid stale/empty mounts. Docker Compose often mounts the repo; build a layer that installs dependencies, or mount only source and keep node_modules inside the container image. With pnpm/yarn workspaces, node_modules may be hoisted—ensure your script runs where they are present.

Frequently asked questions

What does "npm ERR! Error: ENOENT: no such file or directory, stat 'node_modules'" mean?
npm expects node_modules to exist after installs and when resolving binaries. If you run scripts before installing dependencies, mount an empty volume over the project, or execute in the wrong directory, stat on node_modules fails with ENOENT. CI pipelines that clean workspaces, Docker bind mounts that shadow the folder, and monorepos with nested packages commonly see this when running npm run before npm install.
How do I fix "npm ERR! Error: ENOENT: no such file or directory, stat 'node_modules'"?
npm looked for node_modules but it does not exist yet (fresh checkout, cleaned workspace, or wrong working directory). Install dependencies or point npm at the correct folder.
What causes "npm ERR! Error: ENOENT: no such file or directory, stat 'node_modules'"?
Dependencies not installed yet (npm install/ci not run) Volume mount or cache cleared node_modules Misconfigured workdir in CI/Docker
Is the "npm ERR! Error: ENOENT: no such file or directory, stat 'node_modules'" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading