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.

Applies to:npmAll versions on Windows, macOS and Linux
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 rename or lstat with a path inside node_modules during npm install
  • A script fails because a tool such as tsc, vite or eslint is missing, with node_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.json there. 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 no start script).
Damaged node_modules
An interrupted install, manual deletion of files, or broken links in node_modules/.bin leave 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 _cacache or a temp folder.
Missing npm folder on old Windows or a broken install
C:\Users\<user>\AppData\Roaming\npm is 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

Easy

If npm cannot find package.json, the usual reason is that you are one folder too high or too low.

  1. Print the current folder and check whether package.json is in it. On Windows PowerShell use pwd and dir package.json.
    Terminal
    pwd
    ls package.json
  2. If the file is not listed, cd into the folder that contains it, then run your npm command again.

2.Create package.json or add the missing script

Easy

A brand-new folder has no package.json, and an existing one may lack the script you are calling.

  1. In a new project folder, create a default package.json.
    Terminal
    npm init -y
  2. If the error comes from npm start or another script, open package.json and make sure the script is listed under scripts.

3.Install the missing tool

Easy

When the path points at node_modules/.bin/<tool>, the package providing that tool is not installed.

  1. Install the package as a dev dependency. TypeScript is used here as an example.
    Terminal
    npm install typescript --save-dev
  2. Confirm the tool now runs.
    Terminal
    npx tsc --version

4.Reinstall node_modules cleanly

ModerateChanges settings

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.

  1. Remove the installed packages. (rm -rf is a shell command, not an npm command.)
    Terminal
    rm -rf node_modules
  2. Install again.
    Terminal
    npm install
  3. Only if the problem remains and the lockfile may be damaged, remove package-lock.json as well and install again.
    Terminal
    rm -rf node_modules package-lock.json
    npm install

5.Update npm, clear the cache and check disk space

Moderate

Helps when the error mentions _cacache or temp folders, or when installs stop part-way.

  1. Update npm to the latest version.
    Terminal
    npm install -g npm@latest
  2. Clear the npm cache.
    Terminal
    npm cache clean --force
  3. On macOS or Linux, check that the disk is not full.
    Terminal
    df -h
  4. Run your install again.

6.Read the log and check broken links

Moderate

When the cause is not obvious, the log and a few checks show what is really missing.

  1. Check your Node and npm versions and run npm's built-in health check.
    Terminal
    node -v
    npm -v
    npm doctor
  2. Open the debug log file whose path is printed at the end of the error and search it for ENOENT to see the exact missing path.
  3. On macOS or Linux, list broken links in node_modules/.bin.
    Terminal
    find node_modules/.bin/ -type l ! -exec test -e {} \; -print
  4. If node_modules was created by WSL or another operating system, add node_modules to .gitignore, delete it and reinstall on the system you actually run on.

7.Last resort on Windows: check the npm folder

ModerateChanges settings

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.

  1. Press WinR, type %AppData%, and press Enter.
  2. Check that a folder named npm exists. If not, create it.
  3. Right-click the npm folder, 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 ls runs without reporting missing packages, and npx <tool> --version works 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 exact path is the thing to fix.
  • Ask for help in the npm or Node.js community with the full error text, your node -v and npm -v output, 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

  1. Common errors | npm DocsOfficial · npm, Inc.
  2. npm ERR! enoent · sebhastian.com
  3. Fix: npm ERR! enoent ENOENT: no such file or directory · fixdevs