How to fix npm ERR! Error: ENOENT: no such file or directory, open 'package.json' in npm
npm is being run in a directory without package.json or the path is wrong (moved repo, case mismatch, or missing checkout). Switch to the project root or recreate package.json.
Quick fix
Fixes npm ERR! Error: ENOENT: no such file or directory, open 'package.json'
pwd
ls package.json- Verify you are in the project root
- Ensure the file exists and is tracked
- Fix CI/Docker workdir
- Create package.json if starting fresh
pwdls package.jsonnpm ERR! Error: ENOENT: no such file or directory, open 'package.json'
What this error means
npm needs package.json in the current working directory to know what to install or run. If you run npm from the wrong folder, or package.json was deleted/ignored, the fs open call fails with ENOENT and npm exits. This also appears in CI when the working directory is mis-set, when sparse/partial checkouts skip package.json, or on case-insensitive filesystems where path casing differs from git metadata.
Typical symptoms
- npm install/ci fails with ENOENT opening package.json
- Running npm in a subfolder without a package.json
- CI logs show working directory different from repo root
- Sparse checkout or shallow clone missing package.json
- Case mismatch between package.json and filesystem name on macOS/Windows
Common causes
- Running npm in the wrong directory
- package.json deleted, renamed, or .gitignored
- Partial/sparse checkout omitted package.json
- Misconfigured workdir in CI/Docker
- Case-insensitive FS mismatch (Package.json vs package.json)
How to fix "npm ERR! Error: ENOENT: no such file or directory, open 'package.json'"
pwd
ls package.jsonIf missing, cd to the directory that contains package.json.
git status -- package.json
ls -l package.jsonRestore it if deleted or ignored.
Set the job working directory to the repo root (e.g., uses: actions/checkout with working-directory, or docker run -w /app).
npm init -ynpm ciAdvanced notes
Monorepos place package.json in subpackages; ensure you run npm from the package folder or use workspaces. In CI with sparse checkout, include package.json in the sparse set. On macOS/Windows, case-insensitive filesystems can hide casing mistakes—keep the exact lowercase name. If using npm link, confirm the linked package still has its own package.json.
Frequently asked questions
- What does "npm ERR! Error: ENOENT: no such file or directory, open 'package.json'" mean?
- json in the current working directory to know what to install or run. json was deleted/ignored, the fs open call fails with ENOENT and npm exits. json, or on case-insensitive filesystems where path casing differs from git metadata.
- How do I fix "npm ERR! Error: ENOENT: no such file or directory, open 'package.json'"?
- npm is being run in a directory without package.json or the path is wrong (moved repo, case mismatch, or missing checkout). Switch to the project root or recreate package.json.
- What causes "npm ERR! Error: ENOENT: no such file or directory, open 'package.json'"?
- Running npm in the wrong directory package.json deleted, renamed, or .gitignored Partial/sparse checkout omitted package.json
- Is the "npm ERR! Error: ENOENT: no such file or directory, open 'package.json'" 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: package.json reference(Official Docs)
- 📖npm Docs: npm init(Official Docs)
- 💬Stack Overflow: ENOENT opening package.json(Stack Overflow)