npm ERR! code ENOENTNo Such File or Directory — Fixed [2026]
⚡ Check These First — Solves 80% of Cases
Before anything else, run these two checks:
# 1. Are you inside your project folder?
pwd # macOS/Linux — prints current directory
cd # Windows — prints current directory
# 2. Does package.json exist here?
ls # macOS/Linux
dir # WindowsIf package.json is missing or you are in the wrong folder — that is your fix. Navigate to the right directory and run npm install again.
If that wasn't it — every other cause is covered below. The error message itself tells you exactly what went wrong. Read the next section first before jumping to fixes.
What Does npm ERR! code ENOENT Mean?
Here is the full error you are likely seeing:
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /Users/you/projects/myapp/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/Users/you/projects/myapp/package.json'
npm ERR! enoent This is related to npm not being able to find a file.ENOENT is not an npm-specific error — it is a standard operating system error code that stands for Error NO ENTry. It means the OS looked for a file or directory at a specific path and found absolutely nothing there. npm wraps this OS error and adds code ENOENT so you know what category of problem you are dealing with.
The good news: ENOENT is always a path problem. The file either does not exist, is in a different location than npm expects, or the path itself contains a typo or formatting issue. It is never a network error, a permissions issue, or a Node version problem. Once you find the wrong path, the fix is straightforward.
Read Your Error Message Correctly — This Saves You Time
Before reaching for any fix, read your full error output carefully. npm tells you exactly which file it could not find. Look for these two lines:
npm ERR! path /the/exact/path/npm/was/looking/for
npm ERR! enoent ENOENT: no such file or directory, open '/the/exact/path'That path is your diagnosis. Ask yourself:
- Does that file actually exist on disk? (check in your file explorer)
- Is it at a different path than what npm expected?
- Is the filename spelled correctly — including capitalisation?
- On Windows: does the path use backslashes where forward slashes are needed?
Common Paths in the Error → What They Mean
| Path contains... | Likely cause |
|---|---|
| package.json | You are in the wrong directory, or package.json was never created |
| node_modules/... | node_modules is missing — run npm install |
| node_modules/.bin/... | A CLI binary from a package was not installed correctly |
| .npmrc or .nvmrc | Config file is missing or was deleted |
| A script path you defined | Typo in the scripts field of your package.json |
You Are in the Wrong Directory
Most common causeThis is the single most common cause of ENOENT — by a large margin. npm is looking for package.json in your current terminal directory but you are not inside your project folder. It happens after opening a new terminal window, after a CD typo, or when working across multiple projects.
Check where you are
pwdcd
# or
echo %cd%Navigate to your project
cd path/to/your/project
# Example:
cd ~/projects/my-nextjs-app
# Then retry
npm installQuick check: run 'ls' (macOS/Linux) or 'dir' (Windows) and see if package.json appears in the output. If it doesn't — you're in the wrong place.
package.json Is Missing
Fresh projects & cloned reposThere are two common scenarios where package.json genuinely does not exist:
Scenario A — You just cloned a repo
Git never commits node_modules (it's in .gitignore). But package.json is committed. If cloning gave you an ENOENT on package.json, you likely cloned into the wrong folder or the repo itself is misconfigured. Check the repo root:
git clone https://github.com/user/repo.git
cd repo # MUST cd into the cloned folder
npm install # NOW run installScenario B — Brand new project with no package.json
Create one with npm init. The -y flag accepts all defaults and skips the questionnaire:
npm init -y
npm installScenario C — node_modules missing after clone
This is the most common post-clone situation. package.json exists but node_modules does not — because it was never committed. Run:
npm installAlways cd into the cloned repo directory before running any npm command. The folder npm creates on git clone is not automatically your working directory.
Typo in a Script or File Path
npm run errorsIf the ENOENT fires when running npm run something rather than npm install, the problem is almost certainly a typo or wrong path in your scripts section of package.json.
Check your scripts section
{
"scripts": {
"build": "next build",
"dev": "next dev",
"start": "node server.js", // ← does server.js exist?
"lint": "eslint ./src" // ← does ./src exist?
}
}Common typo patterns
- src/index.js but the file is actually src/Index.js (case mismatch — fatal on Linux)
- ./server.js but the file was renamed to app.js
- dist/bundle.js referenced before running the build step that creates it
- A path with a space that is not wrapped in quotes
Verify a file path before adding it to scripts
# macOS / Linux — check if file exists
ls src/index.js
# Windows
dir src\index.jsLinux file systems are case-sensitive. server.js and Server.js are two completely different files on Linux but identical on macOS. A script that works on your Mac can throw ENOENT when deployed to a Linux server for this exact reason.
node_modules Deleted or Corrupted
npm run & require errorsIf ENOENT points to a path inside node_modules — for example node_modules/react/index.js — your node_modules folder is missing, incomplete, or corrupted. This happens after manually deleting packages, a failed install, or disk errors.
The fix is always the same — wipe and reinstall:
macOS / Linux
rm -rf node_modules
npm installWindows — Command Prompt
rmdir /s /q node_modules
npm installWindows — PowerShell
Remove-Item -Recurse -Force node_modules
npm installIf npm install itself throws ENOENT while recreating node_modules, also delete package-lock.json before reinstalling: rm package-lock.json (macOS/Linux) or del package-lock.json (Windows).
Missing File Inside a Dependency Package
Broken or outdated packagesSometimes ENOENT is not your fault at all — a package you installed ships with a broken postinstall script, references a file it forgot to include, or has a bug in a specific version. The error path will point deep inside node_modules/package-name/....
Identify the broken package
Look at the path line in your error. The first folder name after node_modules/ is your culprit package.
Try updating it to the latest patch
npm update package-name
# Or install the latest version explicitly
npm install package-name@latestIf the package is broken and has no fix yet
# Skip postinstall scripts (install without running them)
npm install --ignore-scripts
# Or pin to the last known working version
npm install package-name@1.2.3Check if it is a known issue
Search the package's GitHub issues for ENOENT + the filename from your error. If others are hitting it, there is usually a workaround or patched version in the comments.
Global Package or CLI Binary Not Found
Globally installed packagesIf you are running a globally installed CLI tool — like next, tsc, or eslint — and getting ENOENT, the binary either was not installed globally or was installed to a path that is not in your system PATH.
Check if the package is installed globally
npm list -g --depth=0Install it globally if missing
npm install -g package-nameFind where npm installs global binaries
npm config get prefixThe output of that command + /bin (macOS/Linux) or \bin (Windows) should be in your system PATH. If it is not, add it:
export PATH="$(npm config get prefix)/bin:$PATH"Better approach: instead of installing packages globally, use npx to run them without installing. Example: npx eslint . instead of eslint . — no ENOENT from missing globals ever again.
Windows Path Separator Bug
Windows onlyWindows uses backslashes (\) as path separators. macOS and Linux use forward slashes (/). Most npm packages and scripts are written for Unix and use forward slashes. When a script or config hardcodes a Unix path, Windows cannot find the file — and throws ENOENT.
Example of a broken Windows script
{
"scripts": {
"build": "node scripts/build.js",
"copy": "cp src/assets dist/assets" // cp doesn't exist on Windows
}
}Fixes for Windows path issues
- Use cross-platform packages like cross-env and copyfiles instead of Unix shell commands
- Use path.join() in Node.js scripts instead of hardcoded path strings
- Run npm in WSL (Windows Subsystem for Linux) — full Unix compatibility
- Replace cp/mv/rm commands in scripts with Node.js equivalents using the shelljs package
# Install cross-platform shell utilities
npm install --save-dev cross-env shelljsOS-Specific Notes
macOS
macOS is case-insensitive by default but the file system on Linux servers is case-sensitive. A script referencing src/App.js will work locally on Mac but throw ENOENT when deployed to a Linux server if the real file is src/app.js. Always match casing exactly in import paths and package.json scripts — even on Mac.
Windows
The most Windows-specific ENOENT trigger is paths exceeding 260 characters — the old Windows MAX_PATH limit. Deep node_modules nesting from legacy packages can hit this. Enable long path support in Windows 10/11:
# Enable long paths (Windows 10 1607+ / Windows 11)
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
-Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -ForceAlso check you are not running npm from inside C:\Program Files\ — npm needs write access to its working directory and Program Files is protected.
Linux
Linux is the strictest environment — fully case-sensitive, no tolerance for path separator mixing. Two unique Linux causes of ENOENT: broken symlinks (a symlink pointing to a file that was deleted) and permission-restricted directories where your user cannot read the file even though it exists.
# Check for broken symlinks in node_modules
find node_modules -type l ! -exec test -e {} \; -print
# Check if a file exists but you lack read permission
ls -la path/to/file
# Fix permissions if needed
chmod 644 path/to/fileHow to Prevent npm ENOENT Errors
- Always cd into your project directory before running any npm command — make it a reflex
- Commit package.json and package-lock.json to git — never .gitignore them
- Never commit node_modules — always add it to .gitignore
- Run npm install immediately after cloning any repository
- Match file name capitalisation exactly in all import paths and scripts — even on case-insensitive macOS
- Use npx instead of global installs to avoid missing binary ENOENT errors
- Use cross-env and cross-platform utilities in npm scripts instead of Unix-only shell commands
- Enable Windows long path support if you work on Windows with deeply nested projects
- Test npm scripts on Linux (or WSL) even if you develop on Mac — it catches case-sensitivity bugs before deployment
Quick Diagnosis Checklist
Work through this in order. Stop when you find your cause.
- 1Are you inside your project folder?
pwd / cd - 2Does package.json exist in this folder?
ls / dir - 3Does node_modules exist?
ls node_modules - 4Is the filename in the error spelled correctly?
Check capitalisation - 5Is the script path in package.json correct?
Open package.json → scripts - 6On Windows: is the path using backslashes?
Use cross-env / WSL - 7Is it a broken package postinstall?
npm install --ignore-scripts
Frequently Asked Questions
What does "npm ERR! code ENOENT" mean?+−
Why does npm say no such file or directory when the file clearly exists?+−
How do I fix npm ENOENT missing package.json?+−
npm ENOENT after cloning a repo — why?+−
Can ENOENT be caused by a dependency — not my own code?+−
npm ENOENT on Windows but works on Mac — why?+−
How do I find exactly which file npm cannot find?+−
Need Expert Help?
We Build Production-Grade Next.js & Node.js Apps
Softplix is a full-stack development agency. Hitting complex npm errors in a production project? We can audit your setup and ship a clean, scalable solution.
Talk to an Engineer