Fix: npm ERR! enoent ENOENT: no such file or directory
Quick Answer
How to fix the npm ENOENT no such file or directory error caused by missing package.json, wrong directory, corrupted node_modules, broken symlinks, and npm cache issues.
The Error
You run npm install, npm start, or any npm command and get:
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/user/project/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/home/user/project/package.json'
npm ERR! enoent This is related to npm not being able to find a file.The exact path and syscall vary. You might also see variations like:
npm ERR! enoent ENOENT: no such file or directory, lstat '/home/user/project/node_modules/.bin/vite'npm ERR! enoent ENOENT: no such file or directory, rename '/home/user/.npm/_cacache/tmp/...'npm ERR! enoent ENOENT: no such file or directory, stat '/home/user/project/node_modules/some-package'The common thread: npm tried to access a file or directory that does not exist. The ENOENT error code stands for Error NO ENTry — a standard POSIX error for missing files.
Why This Happens
npm needs specific files to function. When it cannot find them, it throws ENOENT. The root causes fall into several categories:
No
package.jsonin the current directory. You are running npm in the wrong folder, or you never initialized the project.Corrupted or incomplete
node_modules. A failed install, interrupted download, or manual deletion of files insidenode_modulesleaves broken references.Missing binaries referenced by scripts. Your
package.jsonscripts reference a CLI tool (likevite,tsc, oreslint) that is not installed.Broken symlinks. npm uses symlinks in
node_modules/.bin/to point to package executables. If the target package is missing or moved, the symlink breaks.npm cache corruption. The local npm cache at
~/.npm/_cacachecan become corrupted, causing install operations to fail.Global vs local install confusion. You installed a package globally but your project expects it locally, or vice versa.
Case-sensitive file systems. On Linux,
MyComponent.jsandmycomponent.jsare different files. A path that works on macOS or Windows may fail on Linux.
Understanding which file npm cannot find tells you exactly which fix to apply. Read the error message carefully — the path line is the key.
Fix 1: Run npm from the Correct Directory
The most common cause. You are not in the folder that contains package.json.
Check your current directory:
pwdList the files to confirm package.json exists here:
ls package.jsonIf it does not exist, navigate to the correct project root:
cd /path/to/your/projectThen run your npm command again.
If you are inside a subdirectory of your project (like src/ or components/), move up:
cd ..Pro Tip: If you are working in a monorepo with multiple packages, each package has its own package.json. Make sure you are in the specific package directory, not the repo root (unless the root has a package.json too). Tools like npm workspaces or lerna handle this, but running raw npm commands requires you to be in the right folder.
Fix 2: Initialize package.json If It Does Not Exist
If this is a brand-new project and you never created package.json:
npm init -yThis generates a basic package.json with default values. You can edit it afterward.
If you cloned a repository and package.json is missing, something went wrong with the clone. Try again:
git clone <repo-url>
cd <repo-name>
npm installCheck the repository on GitHub or your remote to confirm package.json actually exists in the branch you are using.
Fix 3: Delete node_modules and Reinstall
A corrupted or incomplete node_modules directory causes many ENOENT variations. The fix is a clean reinstall.
On macOS/Linux:
rm -rf node_modules
rm -f package-lock.json
npm installOn Windows (PowerShell):
Remove-Item -Recurse -Force node_modules
Remove-Item -Force package-lock.json
npm installWhy delete package-lock.json too? The lockfile references exact file paths and integrity hashes. If node_modules became corrupted, the lockfile may point to files that no longer match. Regenerating it ensures a clean state.
Note: Deleting package-lock.json means npm will resolve dependency versions fresh. If you need exact version pinning, keep a backup of the lockfile and only delete it as a last resort.
This approach fixes most ENOENT errors related to missing binaries in node_modules/.bin/, broken symlinks, and partially installed packages. If you were seeing errors like ENOENT: no such file or directory, lstat '...node_modules/.bin/vite', this is almost certainly the fix. This same technique works for many npm ERR! code ELIFECYCLE failures too.
Fix 4: Install Missing Packages
Sometimes the ENOENT error points to a specific package binary. For example:
npm ERR! enoent ENOENT: no such file or directory, lstat '/project/node_modules/.bin/tsc'This means typescript is not installed. Install it:
npm install typescript --save-devThe same applies to any missing CLI tool. Match the binary name to its package:
| Binary | Package |
|---|---|
tsc | typescript |
vite | vite |
eslint | eslint |
jest | jest |
next | next |
react-scripts | react-scripts |
nodemon | nodemon |
ts-node | ts-node |
If a script in your package.json references a binary that is not listed in dependencies or devDependencies, add it. This is a frequent source of the missing script error pattern as well.
Fix 5: Fix Global vs Local Install Confusion
You installed a package globally, but your project scripts expect it locally. Or the opposite.
Check if the package exists locally:
ls node_modules/.bin/<package-name>Check if it exists globally:
npm list -g <package-name>If the package is only global but needed locally, install it as a dev dependency:
npm install <package-name> --save-devIf you need it globally and get permission errors on global install, use a Node version manager like nvm or fix your npm prefix.
Common Mistake: Installing packages globally with npm install -g and then expecting them to work in CI/CD pipelines or on other machines. Global installs are machine-specific. Always list project dependencies in package.json so npm install brings everything needed. Reserve global installs for standalone CLI tools you use across all projects (like npm, npx, or nvm).
Fix 6: Clear the npm Cache
A corrupted npm cache causes ENOENT errors during npm install, often with paths containing _cacache or tmp:
npm ERR! enoent ENOENT: no such file or directory, rename '/home/user/.npm/_cacache/tmp/...'Force-clean the cache:
npm cache clean --forceThen reinstall:
rm -rf node_modules package-lock.json
npm installThe --force flag is required because npm does not allow cleaning the cache without it (npm assumes the cache is self-healing). If the cache is truly corrupted, this is the fix.
If cache errors persist, check disk space. A full disk causes write failures that look like ENOENT:
df -hThis kind of cache corruption can also trigger the npm ERR! cb() never called error, so clearing the cache solves both.
Fix 7: Fix Broken Symlinks
npm creates symlinks in node_modules/.bin/ that point to executable files inside installed packages. If those packages are removed or corrupted, the symlinks break.
Check for broken symlinks on macOS/Linux:
find node_modules/.bin/ -type l ! -exec test -e {} \; -printThis lists all symlinks whose targets do not exist. If you see output, your node_modules is in a bad state.
The fix is the same as Fix 3 — delete and reinstall:
rm -rf node_modules package-lock.json
npm installOn Windows, symlinks behave differently. npm uses junction points or .cmd wrapper files instead of Unix symlinks. If these are broken, the clean reinstall approach still works.
Fix 8: Check for Case Sensitivity Issues
This commonly surfaces when deploying from macOS/Windows (case-insensitive) to Linux (case-sensitive).
Your code might import:
const utils = require('./Utils');But the actual file is named utils.js (lowercase). This works on macOS and Windows but fails on Linux with:
Error: ENOENT: no such file or directory, open '/app/src/Utils.js'The fix: match the exact casing of the filename in your import statements.
Find mismatches by listing files and comparing to imports:
ls src/Then update the import to match the real filename exactly. Make this a habit — always use the exact case in require() and import statements. This also prevents cannot find module errors that occur for similar reasons.
Fix 9: Handle npm Workspaces and Monorepo Issues
In a monorepo using npm workspaces, ENOENT errors appear when:
- You run
npm installfrom a package directory instead of the workspace root - A workspace package references another workspace package that has not been linked
Run install from the root of the monorepo (where the top-level package.json with the workspaces field lives):
cd /path/to/monorepo-root
npm installnpm creates symlinks between workspace packages automatically. If those links break, a clean install from the root fixes them.
To run a script in a specific workspace:
npm run build --workspace=packages/my-packageDo not cd into the workspace and run npm install there — it bypasses the workspace linking and causes dependency conflicts, which can cascade into dependency resolution errors.
Fix 10: Verify File Paths in package.json
Your package.json may reference files that do not exist. Check the main, bin, files, and scripts fields:
{
"main": "dist/index.js",
"bin": {
"my-tool": "./bin/cli.js"
},
"scripts": {
"start": "node src/server.js",
"build": "tsc && node dist/build.js"
}
}If dist/index.js does not exist because you have not run the build step, npm throws ENOENT when another package tries to use yours. Run the build first:
npm run buildIf bin/cli.js does not exist, npm throws ENOENT when creating symlinks during install. Verify the path is correct and the file exists.
For scripts, make sure every file path referenced in your npm scripts actually exists. A typo like src/sever.js instead of src/server.js triggers this error immediately.
Still Not Working?
If none of the fixes above resolve the error, try these additional steps.
Check your Node.js and npm versions. Some ENOENT bugs are version-specific:
node -v
npm -vUpdate to the latest LTS version of Node.js. This also updates npm:
nvm install --lts
nvm use --ltsCheck file permissions. On Linux/macOS, if npm cannot read a file, it sometimes reports ENOENT instead of EACCES:
ls -la package.json
ls -la node_modules/Fix permissions if needed:
chmod -R 755 node_modules/Try using npx instead of direct binary calls. If a script references a binary that npm cannot find, npx downloads and runs it on the fly:
npx tsc --versionCheck your .npmrc file. A misconfigured .npmrc can point npm to a registry or cache directory that does not exist:
npm config listLook for cache, prefix, or registry settings that point to invalid paths.
Use npm doctor to diagnose issues. This built-in command checks your npm environment for common problems:
npm doctorIt verifies the cache, registry connectivity, permissions, and Node.js compatibility.
Switch package managers temporarily. If npm’s state is deeply corrupted, try installing with yarn or pnpm to unblock yourself:
npx yarn installor:
npx pnpm installThis does not fix the underlying npm issue but lets you keep working while you debug.
Read the full error log. npm writes detailed logs to a file. The path is shown at the bottom of the error output:
npm ERR! A complete log of this run can be found in:
npm ERR! /home/user/.npm/_logs/2026-03-09T12_00_00_000Z-debug-0.logOpen that file and search for ENOENT. The lines around it often reveal exactly which file operation failed and why.
Solo developer based in Japan. Every solution is cross-referenced with official documentation and tested before publishing.
Was this article helpful?
Related Articles
Fix: Error Cannot find module in Node.js (MODULE_NOT_FOUND)
How to fix 'Error: Cannot find module' and 'MODULE_NOT_FOUND' in Node.js. Covers missing packages, wrong import paths, node_modules issues, TypeScript moduleResolution, ESM vs CJS, and monorepo hoisting.
Fix: SyntaxError: Cannot use import statement outside a module
How to fix 'SyntaxError: Cannot use import statement outside a module' in Node.js, TypeScript, Jest, and browsers by configuring ESM, package.json type, and transpiler settings.
Fix: FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
How to fix the JavaScript heap out of memory error by increasing Node.js memory limits, fixing memory leaks, and optimizing builds in webpack, Vite, and Docker.
Fix: npm ERR! cb() never called
Resolve npm's cb() never called error by clearing cache, fixing network issues, updating npm, and resolving corrupted package-lock.json files.