How to Fix "npm ERR!" — ERESOLVE, E404, EACCES and More
Every npm error starts with npm ERR! — the fix depends on the code. Here is what ERESOLVE, ELIFECYCLE, E404, ENOENT and EACCES mean, and how to resolve each.
npm ERR! is just a prefix on any npm failure — the actionable part is the code line right below it. Each code is a distinct family with a distinct fix, so read the code first: it tells you whether this is a dependency conflict, a script failure, a registry miss, a wrong directory, or a permissions problem.
ERESOLVE — peer dependency conflict
Since npm 7, peer dependencies are enforced strictly. npm ERR! code ERESOLVE ... unable to resolve dependency tree means two packages demand incompatible versions of a shared peer.
# pragmatic fix — install with npm 6-style peer handling
npm install --legacy-peer-deps
# proper fix — align the versions the conflict names
npm install react@18 react-dom@18
# persist it for the project if needed (.npmrc)
echo "legacy-peer-deps=true" >> .npmrc
ELIFECYCLE / "Missing script" — a script failed or does not exist
Either the scripts key is absent, or the command it runs exited non-zero.
# see the real script names
npm run
# "Missing script: build" -> add it to package.json "scripts"
# ELIFECYCLE errno 1 -> the real error is printed ABOVE this line, scroll up
E404 — package or version not found
A typo in the name, an unpublished version, or a private/scoped package without auth. npm ERR! 404 Not Found - GET https://registry.npmjs.org/<pkg>.
# check the real name and available versions
npm view express versions
# scoped/private package -> authenticate + point the scope at a registry
npm login
# .npmrc: @myorg:registry=https://your-registry/
ENOENT — a file or path is missing
Usually npm ran in a directory with no package.json: npm ERR! enoent ... open '/path/package.json'.
# run from the project root (the folder with package.json)
cd path/to/project
# starting fresh? create one first
npm init -y
# stale node_modules ENOENT:
rm -rf node_modules package-lock.json && npm install
EACCES — permission denied
npm cannot write, usually to a global directory owned by root from an earlier sudo install: EACCES: permission denied, access '/usr/lib/node_modules'.
# recommended: use a version manager so the global dir is user-owned
# (nvm / fnm), then reinstall globals without sudo
# or set a user-owned prefix
npm config set prefix ~/.npm-global # add ~/.npm-global/bin to PATH
# repair ownership if needed
sudo chown -R $(whoami) ~/.npm
Quick diagnostic checklist
- Read the
npm ERR! codeline first — it names the family and the fix path. - ERESOLVE? Read the "Conflicting peer dependency" block; try
--legacy-peer-deps, then plan a version alignment. - Missing script? Run
npm runwith no arguments to list the real script names. - E404? Re-check the name with
npm view <pkg>; confirm registry/auth for scoped packages. - ENOENT / EACCES? Confirm you are in the project root; fix directory ownership instead of using
sudo.
Frequently asked questions
What is the difference between --legacy-peer-deps and --force?
--legacy-peer-deps only relaxes peer-dependency checks, mimicking npm 6 — usually safe. --force bypasses every safety check and can install a broken dependency tree. Try legacy-peer-deps first; keep --force as a last resort.Why does npm ci fail when npm install works?
npm ci requires package.json and package-lock.json to be in sync and fails hard on any mismatch, by design. Run npm install locally to regenerate and commit the lockfile, then CI’s npm ci will succeed.Should I use sudo to fix npm EACCES?
sudo npm install. Fix it by using a version manager (nvm/fnm) or a user-owned prefix, and repair ownership with chown — do not routinely run npm with sudo.Want to skip the local toolchain entirely for a quick test? XCODX Studio runs npm packages in the browser over import maps — no node_modules, no install errors, nothing to configure.