How to fix npm ERR! Error: ENOENT: no such file or directory, stat 'node_modules' in npm
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- Confirm the working directory
- Install dependencies
- Handle Docker/CI mounts
- For monorepos, run in the package directory
pwdls node_modules 2>/dev/nullnpm 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
- Dependencies not installed yet (npm install/ci not run)
- Volume mount or cache cleared node_modules
- Misconfigured workdir in CI/Docker
- Monorepo path confusion; running at root instead of package
- npm cache/node_modules removed by cleanup script
How to fix "npm ERR! Error: ENOENT: no such file or directory, stat 'node_modules'"
pwd
ls node_modules 2>/dev/nullnpm ci
# or
npm installEnsure your container workdir matches the project root and that you are not mounting an empty host folder over node_modules.
If using workspaces, run npm inside the specific package that owns node_modules or enable workspaces at the root.
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
- 📚npm Official Documentation
- 📖npm Docs: npm ci(Official Docs)
- 📖npm Docs: node_modules folder(Official Docs)
- 💬Stack Overflow: ENOENT stat node_modules(Stack Overflow)