npx keeps running an old version instead of the newest release
npx runs an older version than the one just publishedShort 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.
Fix it fast
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>2Match what you see, then jump to its fix
- 1
npm ls shows the package in the project you are standing inThe package is already a dependency of your projectFix - 2
Outside any project, npx still runs the old release after you published a new onenpx uses a version from the npm cacheFix - 3
You need a particular release for a scriptYou did not name the version you wantFix
- 1
What does the error look like?
npx runs an older version than the one just publishedmy-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>@latest3Verify
The version printed by npx is the newer one.
npx <package> --versionConfirmed by docs.npmjs.com
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> version2Fix
Add --prefer-online to refresh the cache check.
npx --prefer-online <package>3Verify
npx runs the version npm view reports.
npx <package> --versionConfirmed by docs.npmjs.com
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 --json2Fix
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 --versionConfirmed by docs.npmjs.com
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
npx stops with 'could not determine executable to run'
npm ERR! could not determine executable to run
npx picks the command from the package's bin field.
3 causes, each with a fixBack 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 fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack 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 fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fix