npm install fails with 404 Not Found for a package that exists
npm ERR! Error: 404 Not FoundShort answer
A 404 from npm means the registry that npm asked has no such package for you. Check which registry the package's scope is mapped to, because a scope can point at a private registry. Scoped packages are private by default, so a missing login or access gives 404 too. Retry later if the registry had a glitch.
Fix it fast
1Find out which cause you have
Print every npm setting that applies, including .npmrc files in the project and in your home folder. Look for the registry line and for any line that starts with the package scope.
npm config ls -l2Match what you see, then jump to its fix
- 1
The 404 URL has a host that is not registry.npmjs.org, or a scoped package fails while unscoped ones installThe scope is mapped to a different registryFix - 2
The package is scoped (@myorg/name) and you published it yourself or got it from a teamA scoped package is private and you are not signed inFix - 3
The same install worked an hour ago and fails for a package you did not changeA short registry problemFix
- 1
What does the error look like?
npm ERR! Error: 404 Not Found
Cause 1 of 3
The scope is mapped to a different registry
1Check
A scope can be mapped to a registry, and installs for that scope then go to that registry. The default registry is https://registry.npmjs.org/. A stale mapping in a project or user .npmrc sends the request to a server that does not host the package.
npm config ls -l | grep -i registry
cat .npmrc ~/.npmrc2Fix
Point the scope at the registry that really hosts the package, or remove the mapping to use the default registry.
npm config set @myorg:registry=https://registry.npmjs.org/3Verify
Run the install again.
npm install @myorg/mypackageConfirmed by docs.npmjs.com
Cause 2 of 3
A scoped package is private and you are not signed in
1Check
Scoped packages are private by default, and the first public publish needs an access flag. Check how the package was published and whether you are logged in to the registry that holds it.
npm config ls -l | grep -i registry2Fix
Log in with an account that has access. If the package should be public, the owner publishes it with the public access flag.
npm login
# owner, for a public scoped package:
npm publish --access public3Verify
Install the package again.
npm install @myorg/mypackageConfirmed by docs.npmjs.com
Cause 3 of 3
A short registry problem
1Check
The npm documentation calls a one-off 404 most likely a temporary registry glitch. Check the registry status page before changing your setup.
npm install2Fix
Wait a short while and run the install again. If it keeps failing for one package version, ask the package owner to publish a fixed version.
npm install3Verify
The install finishes without a 404.
npm ls --depth=0Confirmed by docs.npmjs.com
How do I stop it coming back?
- Commit a project .npmrc that maps each private scope to its registry, and keep tokens out of it.
- Review ~/.npmrc when a laptop or CI image is reused for another client or team.
- Use npm login on CI through the registry's own token mechanism, never through a pasted password.
- Install from a lock file so one outage does not change which versions you resolve.
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 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 fixBack end
The command npm run build -- --prod exited with code 1 (Angular)
The command "npm run build -- --prod" exited with code 1
Exit code 1 only says the build failed; the real message is above it.
2 causes, each with a fix