npm error code ENOENT: no such file or directory, how to fix it
`npm error code ENOENT` means npm, or a script it started, tried to open a file or folder that does not exist. The `syscall` and `path` lines in the log show which one. Most often you are in the wrong folder or `node_modules` is damaged, and changing folders or reinstalling fixes it.
On this page
What it means
ENOENT is a standard system error code. npm shows it when it, or a script it started, hits a missing file or folder. It is not one single bug, so the first line alone does not tell you the fix.
The useful part is a few lines further down. Look at syscall (for example open, rename or lstat) and path. Together they show what was missing. Newer npm versions print npm error at the start of each line, older ones print npm ERR!. The cause and the fix are the same either way.
A note on the sources: the official npm page on this error covers only two old cases. The steps below are the ones that two independent troubleshooting articles agree on, so treat them as community-tested advice rather than vendor-documented procedure.
Symptoms and causes
You are likely dealing with this problem if:
npm error enoent Could not read package.json: Error: ENOENT: no such file or directory, open '/path/package.json'npm error syscall renameorlstatwith a path insidenode_modulesduringnpm install- A script fails because a tool such as
tsc,viteoreslintis missing, withnode_modules/.bin/<tool>in the error
The usual causes, most common first:
- Wrong folder
- npm was run in a parent or child folder of the project, so there is no
package.jsonthere. This is the most common cause. - Missing package.json or script
- The project has no
package.json, or it has no entry for the script you ran (for example nostartscript). - Damaged node_modules
- An interrupted install, manual deletion of files, or broken links in
node_modules/.binleave a half-installed tree. - Tool not installed
- A script calls a program (such as
tsc) whose package was never installed. - Cache or disk problems
- A corrupted npm cache or a full disk. The path in the error often mentions
_cacacheor a temp folder. - Missing npm folder on old Windows or a broken install
C:\Users\<user>\AppData\Roaming\npmis missing. The official npm docs tie this to Windows 7-era Node installers, so it is an unlikely cause on current Windows.
How to fix it
Work through these in order. They start with the quickest, safest checks and move to deeper repairs; stop as soon as the problem is gone.
1.Check that you are in the project folder
If npm cannot find package.json, the usual reason is that you are one folder too high or too low.
- Print the current folder and check whether
package.jsonis in it. On Windows PowerShell usepwdanddir package.json.pwd ls package.json - If the file is not listed,
cdinto the folder that contains it, then run your npm command again.
2.Create package.json or add the missing script
A brand-new folder has no package.json, and an existing one may lack the script you are calling.
- In a new project folder, create a default
package.json.npm init -y - If the error comes from
npm startor another script, openpackage.jsonand make sure the script is listed underscripts.
3.Install the missing tool
When the path points at node_modules/.bin/<tool>, the package providing that tool is not installed.
- Install the package as a dev dependency. TypeScript is used here as an example.
npm install typescript --save-dev - Confirm the tool now runs.
npx tsc --version
4.Reinstall node_modules cleanly
Fixes a half-installed or damaged node_modules, including broken .bin links.
Before you start: Deleting package-lock.json can change the dependency versions you get, so keep it unless you suspect the lockfile itself is broken. Run these commands only inside the project folder.
- Remove the installed packages. (
rm -rfis a shell command, not an npm command.)rm -rf node_modules - Install again.
npm install - Only if the problem remains and the lockfile may be damaged, remove
package-lock.jsonas well and install again.rm -rf node_modules package-lock.json npm install
5.Update npm, clear the cache and check disk space
Helps when the error mentions _cacache or temp folders, or when installs stop part-way.
- Update npm to the latest version.
npm install -g npm@latest - Clear the npm cache.
npm cache clean --force - On macOS or Linux, check that the disk is not full.
df -h - Run your install again.
6.Read the log and check broken links
When the cause is not obvious, the log and a few checks show what is really missing.
- Check your Node and npm versions and run npm's built-in health check.
node -v npm -v npm doctor - Open the debug log file whose path is printed at the end of the error and search it for
ENOENTto see the exact missing path. - On macOS or Linux, list broken links in
node_modules/.bin.find node_modules/.bin/ -type l ! -exec test -e {} \; -print - If
node_moduleswas created by WSL or another operating system, addnode_modulesto.gitignore, delete it and reinstall on the system you actually run on.
7.Last resort on Windows: check the npm folder
The official npm docs list a missing npm folder under your user profile as a cause, but they describe it for Windows 7-era Node installers. On Windows 10 or 11 this is unlikely to help, so try it only after the steps above, for example if the path in the error points into AppData\Roaming\npm.
Before you start: Change permissions only for your own user account on this one folder. Do not run npm as administrator to get around it, and do not use chmod -R or similar blanket permission changes.
- Press WinR, type
%AppData%, and press Enter. - Check that a folder named
npmexists. If not, create it. - Right-click the
npmfolder, choose Properties, open the Security tab and confirm your own user account has write permission. Adjust only that entry if it does not. Then run npm again.
Check that it worked
- Run the command that failed again and confirm it finishes without
npm error code ENOENT. npm lsruns without reporting missing packages, andnpx <tool> --versionworks for any tool you installed.
If it still fails
- Read the debug log file named at the end of the error and search for
ENOENT. The exactpathis the thing to fix. - Ask for help in the npm or Node.js community with the full error text, your
node -vandnpm -voutput, and your operating system.
Questions
Is it safe to delete node_modules?
It only holds installed packages and is recreated by npm install. Delete package-lock.json only if you accept that dependency versions may change.
Sources
- Common errors | npm DocsOfficial · npm, Inc.
- npm ERR! enoent · sebhastian.com
- Fix: npm ERR! enoent ENOENT: no such file or directory · fixdevs