Maaz Zindani

Loading the index…

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

npx keeps running an old version instead of the newest release

Errornpx runs an older version than the one just published

Short answer

npx (npm exec) checks your project first: a package without a version specifier is matched to the version in your local dependencies, and local bins are always on the PATH. Otherwise it uses the npm cache. Name the version, or add --prefer-online so the cache is checked for updates.

  • Applies to npm 10-11, Node.js 22, Node.js 24
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check which version a plain npx call resolves to, and whether your project already depends on the package.

    npx <package> --version
    npm ls <package>
  2. 2Match what you see, then jump to its fix

    1. 1npm ls shows the package in the project you are standing inThe package is already a dependency of your projectFix
    2. 2Outside any project, npx still runs the old release after you published a new onenpx uses a version from the npm cacheFix
    3. 3You need a particular release for a scriptYou did not name the version you wantFix

What does the error look like?

  • npx runs an older version than the one just published
  • my-tool --version prints an old number after npm publish

Cause 1 of 3

The package is already a dependency of your project

1Check

npm exec matches a name with no specifier to whatever version exists in your local project, and locally installed bins are always present in the PATH. The --ignore-existing option was removed.

npm ls <package>

2Fix

Update the local dependency, or run npx from a folder that does not depend on it.

npm install <package>@latest
# or run from a different folder
cd ~ && npx <package>@latest

3Verify

The version printed by npx is the newer one.

npx <package> --version

Confirmed by docs.npmjs.com

Did this fix it?

Cause 2 of 3

npx uses a version from the npm cache

1Check

When you give a package name, npm uses its internal package cache. --prefer-online makes it look for updates right away even when the package is in the cache.

npm view <package> version

2Fix

Add --prefer-online to refresh the cache check.

npx --prefer-online <package>

3Verify

npx runs the version npm view reports.

npx <package> --version

Confirmed by docs.npmjs.com

Did this fix it?

Cause 3 of 3

You did not name the version you want

1Check

The command form takes package@version, which fetches that package version.

npm view <package> versions --json

2Fix

Write the version in the npx call, and use the package flag when the command name differs from the package name.

npx <package>@1.4.2 --version
npx --package=<package>@1.4.2 -- <command>

3Verify

The printed version is the one you named.

npx <package>@1.4.2 --version

Confirmed by docs.npmjs.com

Did this fix it?

How do I stop it coming back?

  • Pin the version in the npx call inside scripts, so every machine runs the same release.
  • Use npm view <package> version to confirm what the registry has published.
  • Remember that a local dependency wins over a remote download.

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

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.