Fix: npm ENOENT Error
npm can't find a file or directory it expects. Almost always: wrong directory, missing package.json, or a corrupted install.
Last updated: October 2026
Check the path in the error message. ENOENT always names the specific file that's missing. That path tells you exactly what's wrong:
# If the error says:
ENOENT: no such file or directory, open '/Users/you/package.json'
↑
wrong directory
# Fix:
cd /correct/path/to/your/project
npm install
Wrong directory is the #1 cause. Rule it out in 5 seconds.
The 5 real causes
Wrong directory
You ran npm install outside your project folder. npm looked for package.json, didn't find one, and threw ENOENT.
Check:
# Where am I?
pwd
# Is package.json here?
ls package.json # macOS/Linux
dir package.json # Windows
# If not, find it
cd path/to/your/project
npm install
Pro tip: If you have a monorepo, run npm from the package folder, not the root. Or use workspaces.
Missing or corrupted node_modules
npm expects files inside node_modules that aren't there. Usually from an interrupted install or a partially-deleted folder.
# Full clean reinstall — fixes 90% of these
rm -rf node_modules package-lock.json
npm cache clean --force
npm install
# Windows equivalent
rmdir /s /q node_modules
del package-lock.json
npm cache clean --force
npm install
If you're on a team: Never commit node_modules. Delete it whenever it gets weird. Reinstall is 30 seconds and solves more problems than it creates.
Script references missing file
The error happens when running npm run X, not npm install. Your script command references a file that doesn't exist yet.
// package.json
{
"scripts": {
"start": "node dist/index.js" ← dist/ doesn't exist yet
}
}
# Fix — build first
npm run build
npm start
# Or the file path is wrong
"start": "node src/indedx.js" ← typo
# Check with
ls src/ # verify file names
package-lock.json corruption
The lockfile references packages or paths that don't exist. Common after a partial Git merge or a bad npm update.
# Safe fix — regenerate the lockfile
rm package-lock.json
npm install
# If that doesn't help, also clear node_modules
rm -rf node_modules package-lock.json
npm install
Pro tip: Commit package-lock.json to git. If it gets corrupted, git checkout package-lock.json restores the last working version.
Permissions or symlink issues
npm can't read a file it expects. This shows up as ENOENT when the path exists — usually a permission or symlink problem.
# Check if the path exists and its permissions
ls -la /path/to/missing/file
# If it's a broken symlink
ls -la node_modules/.bin/
# Fix symlinks (common on Windows + WSL, or after moving the project)
rm -rf node_modules
npm install
If you moved your project folder on disk, symlinks inside node_modules/.bin/ break. Reinstalling regenerates them.
ENOENT variants and their exact fixes
| Error message | Fix |
|---|---|
| ENOENT: no such file or directory, open 'package.json' | Wrong directory. cd into your project folder. |
| ENOENT: no such file or directory, open 'node_modules/...' | Clean reinstall: rm -rf node_modules package-lock.json && npm install |
| ENOENT: no such file or directory, scandir | Directory exists but is unreadable. Check permissions. |
| ENOENT: no such file or directory, rename | File move failed mid-install. Clean reinstall. |
| ENOENT: no such file or directory, chmod | Permission issue. See the EACCES fix. |
🛡️ How to prevent ENOENT
- Always
cdinto your project root before running npm. Usepwdto confirm. - Commit
package-lock.json. Never gitignore it. It's how npm knows exactly which versions to install. - Gitignore
node_modules. It should never be in version control. - Add a
preparescript that builds before running:"prepare": "npm run build". - Use
npm ciin CI. It installs from the lockfile exactly and fails if the lockfile is out of sync. - Don't move project folders with node_modules inside. Delete node_modules, move the project, then reinstall.
❓ Frequently asked questions
What causes npm ENOENT errors?
ENOENT means 'Error NO ENTry' — a file or directory npm expected doesn't exist. Common causes: running npm commands outside your project folder (missing package.json), a script referencing a missing file, or a corrupted node_modules install.
How do I fix npm ENOENT: no such file or directory, open package.json?
;You're running npm in the wrong directory. cd into your project folder first. Check with 'ls package.json' or 'dir package.json' that the file exists. If not, either you're in the wrong folder or the project needs to be initialized with npm init.
What does ENOENT open node_modules mean?
npm tried to read a file inside node_modules that doesn't exist. Usually a corrupted install. Fix: delete node_modules and package-lock.json, then run npm install fresh.
How do I fix ENOENT for missing scripts?
Your package.json scripts section references a file that doesn't exist. Check the script command in package.json against your file structure. Common case: 'node dist/index.js' but dist/ wasn't built yet — run npm run build first.
Does npm cache cause ENOENT?
Rarely, but cache corruption can trigger ENOENT during install. Fix: npm cache clean --force, then delete node_modules and reinstall.