Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

npm is broken and will not update itself: reinstall it the supported way

Errornpm does not support Node.js v<version>

Short answer

A broken npm cannot always repair itself, so replace the whole Node.js install instead of patching it. Install nvm, install an LTS Node version (npm comes with it), run nvm install-latest-npm if you need the newest npm for that Node, and verify the cache with npm cache verify. The npm docs recommend a version manager over a plain installer.

  • Applies to Node.js 22 LTS, npm 10, nvm
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    See what is installed and where the shell finds it, before you remove anything.

    which node npm
    node -v
    npm -v
  2. 2Match what you see, then jump to its fix

    1. 1npm prints that it does not support your Node.js version, or fails right after a Node upgrade.npm and Node.js versions do not matchFix
    2. 2npm install -g npm@latest fails because npm itself cannot run, or global installs fail on permissions.Node.js was installed with a plain installer and npm is damagedFix
    3. 3npm runs, but installs fail with strange integrity or fetch errors, or your npm is behind Node's bundled one.npm works but the cache or npm version is the problemFix

What does the error look like?

  • npm does not support Node.js v<version>
  • EACCES

Cause 1 of 3

npm and Node.js versions do not match

1Check

nvm's README describes this exact case: npm is not upgraded automatically when you reinstall packages, so it can end up broken for the new Node.

nvm ls

2Fix

Go back to a Node version that worked, delete the broken one, and install again with --latest-npm so npm is updated at the same time.

nvm use <last-working-version>
nvm uninstall <broken-version>
nvm install --latest-npm 'lts/*'

3Verify

node and npm both print versions.

node -v && npm -v

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 3

Node.js was installed with a plain installer and npm is damaged

1Check

The npm docs recommend a Node version manager and advise against a Node installer, because the installer puts npm in a directory with local permissions and can cause permission errors when you run npm packages globally.

which node

2Fix

Install a version manager such as nvm, then install Node.js through it. The npm docs say you do not need to remove the current Node.js or npm first.

nvm install 22
nvm use 22

3Verify

which node now points inside the nvm folder.

which node npm

Confirmed by docs.npmjs.com

Did this fix it?

Cause 3 of 3

npm works but the cache or npm version is the problem

1Check

npm cache verify garbage-collects unneeded data and checks the integrity of the cache index and cached data. The docs add that clearing the cache is rarely needed because it is self-healing.

npm cache verify

2Fix

Verify the cache, then upgrade npm itself to the latest release.

npm cache verify
npm install -g npm@latest

3Verify

Re-run the install that failed.

npm -v && npm install

Confirmed by docs.npmjs.com

Did this fix it?

How do I stop it coming back?

  • Manage Node.js with nvm or another version manager instead of a system installer.
  • After changing Node versions, run nvm install-latest-npm.
  • Do not delete files inside the npm folder by hand.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

npm install worked but the command is not found

bash: vite: command not found

npm puts a local install's command in the project's node_modules/.bin, which is not on your shell PATH, so run it with npx or from an npm script.

3 causes, each with a fix

Back end

ng serve says it cannot determine the project or target

Cannot determine project for command.

The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.

3 causes, each with a fix

Back end

ng serve cannot find the dev-server builder package

Could not find the implementation for builder @angular/build:dev-server

The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.