Skip to content
npm ERR! code ENOENT

npm ERR! code ENOENT

DodaTech 2 min read

The npm ERR! code ENOENT error means npm cannot find a file or directory, usually package.json. Fix it by running npm init or checking your working directory.

What It Means

ENOENT is a low-level POSIX error code that means “No such file or directory.” When npm shows this error, it could not find a critical file it expected to exist at a specific path. The error message usually includes the missing path: ENOENT: no such file or directory, open '/path/to/package.json'.

Why It Happens

  • You’re running npm install or npm start in a directory without a package.json.
  • A package.json references a file (e.g., a "main" entry) that doesn’t exist.
  • The node_modules directory was deleted or corrupted mid-operation.
  • You renamed or moved a project folder after installing dependencies.
  • A symlink used by npm is broken or points to a non-existent location.

How to Fix It

1. Check your working directory

pwd                        # print working directory
ls package.json            # confirm package.json exists

If package.json is missing, create one:

npm init -y

This generates a default package.json and resolves the most common ENOENT case.

2. Verify the full error path

Read the complete error message — it shows the exact missing path:

npm install 2>&1 | grep "ENOENT"

For example, ENOENT: no such file or directory, open '/home/user/project/src/config.json' — check if that file exists or if the path is wrong.

3. Reinstall dependencies

If node_modules is corrupted or missing:

rm -rf node_modules package-lock.json
npm install

4. Check the "main" field in package.json

cat package.json | grep '"main"'

If it points to a file that doesn’t exist (e.g., "main": "dist/index.js" but dist/ is empty), either build your project or update the field.

5. Fix broken symlinks

On Linux / macOS:

find node_modules -type l ! -exec test -e {} \; -print

Remove any broken symlinks found, then reinstall dependencies.

Does ENOENT mean npm is broken?
No — ENOENT is a file-system error code, not an npm bug. It means the path npm was told to access does not exist. The fix is almost always to create the missing file, correct a path, or run npm init to generate package.json.
Can ENOENT happen with global packages?
Yes. If a globally installed tool (like create-react-app or nest) tries to access a file in your project directory that doesn’t exist, npm will throw ENOENT. This is why checking the full error path is critical — it tells you exactly what’s missing.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro