npm ERR! code ENOENT
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 installornpm startin a directory without apackage.json. - A
package.jsonreferences a file (e.g., a"main"entry) that doesn’t exist. - The
node_modulesdirectory 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 existsIf package.json is missing, create one:
npm init -yThis 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 install4. 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 {} \; -printRemove any broken symlinks found, then reinstall dependencies.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro