npm install errors: how to read them and fix the common ones
Tested: we reproduced this error and confirmed the fix on Node 22.23 with npm 10.9.9 on Ubuntu 24.04, November 29, 2026.
Find the line that says code. It names the kind of failure, and each code has its own fix:
npm error code ENOENT
Match it in the table below. npm 10 prints npm error, and older versions print npm ERR!. The codes are the same. We reproduced each error here with npm 10.9.
npm error codes and fixes
| Code | What it means | Fix |
|---|---|---|
ERESOLVE |
Two packages need different versions of the same peer dependency | See npm ERESOLVE |
ENOENT |
A file npm needs doesn’t exist, usually package.json |
cd into the project folder. See npm ENOENT |
EACCES |
You don’t have permission to write somewhere, usually the global folder | Change npm’s global prefix (below), don’t use sudo |
E404 |
The package name doesn’t exist on the registry, or it’s private | Check the spelling, or log in to the right registry |
ETARGET |
The version you asked for doesn’t exist | npm view <package> versions and pick a real one |
EBADENGINE |
The package says it needs a different Node or npm version | Switch Node versions, or treat it as a warning |
EJSONPARSE |
Your package.json isn’t valid JSON |
Fix the line and column it names |
1 (with command failed) |
A package’s install script failed, often a native build | Read the output above command failed |
ENOTFOUND, ETIMEDOUT, ECONNRESET |
npm couldn’t reach the registry | Check your connection, proxy and npm config get registry |
EACCES on global installs
Installing a package with -g into a folder you don’t own failed like this:
npm error code EACCES
npm error syscall mkdir
npm error path /tmp/gprefix/lib
npm error errno -13
npm error Error: EACCES: permission denied, mkdir '/tmp/gprefix/lib'
npm’s guide to EACCES errors gives two fixes: reinstall Node with a version manager (its recommended option), or point npm’s global folder at one you own. For the second, npm’s example uses ~/.local. We used a dedicated folder so npm’s files stay separate:
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.zshrc
In our test, after npm config set prefix, the same user’s npm install -g left-pad worked and ~/.npmrc held prefix=/tmp/nh2/.npm-global. Use ~/.bashrc if your shell is bash.
If npm instead says Your cache folder contains root-owned files, an earlier sudo npm left files owned by root in ~/.npm. We triggered this one by accident, and npm printed the fix itself: a sudo chown -R command for the cache folder. Run the command it prints.
E404 and ETARGET: the package or version doesn’t exist
For a name that doesn’t exist, npm printed npm error 404 Not Found - GET https://registry.npmjs.org/<name> - Not found and '<name>@*' is not in this registry. Check the spelling and the scope (@company/name). For a private package, log in with npm login or set the registry for that scope in .npmrc.
For a version that doesn’t exist (we asked for left-pad@99.0.0), npm printed npm error notarget No matching version found for left-pad@99.0.0. List the real versions:
npm view left-pad versions
EBADENGINE: wrong Node version
When engines in package.json asked for Node 99, npm install printed npm warn EBADENGINE Unsupported engine with the required and current versions, then installed anyway. With --engine-strict it became npm error code EBADENGINE and stopped. If a package really needs a newer Node, switch versions with a version manager such as nvm.
npm error code 1: a build script failed
Some packages run a script when they install, often to compile native code. When ours exited with an error, npm printed:
npm error code 1
npm error path /tmp/nc/app/node_modules/dep
npm error command failed
npm error command sh -c node -e "..."
npm error gyp: build failed
The path line names the package. The lines after command are that script’s own output, and they hold the real cause. Common ones are a missing compiler (on a Mac, install the Xcode Command Line Tools), a Python version node-gyp doesn’t support, or a package too old for your Node version. Upgrading that package often fixes it.
npm install --ignore-scripts skipped the script and finished in our test, but the package may not work without its build step. Use it to confirm which package is failing, not as the fix.
When nothing else works
Start from a clean install, keeping the lockfile:
rm -rf node_modules
npm cache verify
npm install
If the error mentions a missing file under node_modules, this usually clears it. Run npm install --loglevel=verbose to see every step when the short error isn’t enough. npm also saves a full log, and the last line of the error gives its path.
FAQ
How do I know if npm is installed?
Run npm --version and node --version in a terminal. If both print a version number, they're installed. If you get "command not found" or "not recognized", install Node.js, which includes npm, and open a new terminal.
Why can't I run npm start?
Usually because the project has no start script. npm 10.9 printed npm error Missing script: "start" in our test. Check the scripts section of package.json for the right name (often dev), and run it with npm run dev. If npm can't find package.json at all, you're in the wrong folder.
Why is npm install not working in Visual Studio Code?
VS Code's terminal runs in the folder you opened, which may not be the folder with package.json. It also keeps the PATH from when VS Code started, so after installing Node, restart VS Code. Otherwise the errors are the same as in any terminal.
What does npm error code 1 mean?
A script that a package runs during install (often a native build with node-gyp) exited with an error. The real cause is in the lines just above or below command failed, so scroll up and read the package name and its output.
Should I use sudo npm install?
No. For permission errors on global installs, npm's docs recommend using a Node version manager or changing npm's global folder to one you own. Running npm with sudo can leave root-owned files that cause more EACCES errors later.
