npm ENOENT no such file or directory — how to fix

# Most common fix — reinstall node_modules
rm -rf node_modules package-lock.json
npm install

# Or clear npm cache and reinstall
npm cache clean --force
npm install
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 'package.json'

npm cannot find a required file. Most commonly package.json is missing (you are in the wrong directory) or node_modules is corrupted.

Wrong working directory

# Make sure you are in the project root
ls package.json   # should exist
cd my-project
npm install

Missing package.json — initialize a new project

npm init -y   # create package.json with defaults

Path issues with npm scripts

If a script references a file that does not exist, you get ENOENT when running it.

# package.json scripts
"scripts": {
  "build": "node scripts/build.js"   # ← scripts/build.js must exist
}