npm install fails with EUNSUPPORTEDPROTOCOL
npm ERR! code EUNSUPPORTEDPROTOCOLShort answer
npm raises EUNSUPPORTEDPROTOCOL when a dependency in package.json uses a spec form npm does not know. The usual one is workspace:, which Yarn and pnpm define but npm's documented forms do not include. Replace it with a version range of the workspace name, or install with the tool the repo was made for.
Fix it fast
1Find out which cause you have
Find the dependency value that is not a version range, URL, file: path or git form.
grep -nE '"[^"]+": "[a-z]+:' package.json */package.json packages/*/package.json2Match what you see, then jump to its fix
What does the error look like?
npm ERR! code EUNSUPPORTEDPROTOCOLnpm error code EUNSUPPORTEDPROTOCOL
Cause 1 of 2
A workspace: dependency installed with npm
1Check
The workspace: prefix is a Yarn and pnpm protocol for linking monorepo packages. npm's package.json docs list versions, tarballs, git URLs, file: paths and aliases, and npm's workspaces docs link packages by their name.
grep -rn "workspace:" --include=package.json . | grep -v node_modules
ls pnpm-workspace.yaml yarn.lock .yarnrc.yml 2>/dev/null2Fix
If the repo uses pnpm or Yarn (look for pnpm-workspace.yaml or yarn.lock), install with that tool. If it should be an npm monorepo, list the folders under workspaces in the root package.json and replace each workspace: value with a version range of that package's name.
// root package.json
{ "workspaces": ["packages/*"] }
// a package that needs another one
"dependencies": { "@acme/shared": "^1.0.0" }3Verify
Run the install from the repo root.
npm installConfirmed by pnpm.io
Cause 2 of 2
A URL or path spec is not in a documented form
1Check
npm install accepts a tarball URL only when it begins with the protocol, a git remote with git, git+ssh, git+http, git+https or git+file, and local folders and tarballs by path.
grep -nE '"(git|http|https|file|github)[^"]*"' package.json2Fix
Write the dependency in one of the documented forms.
"dependencies": {
"tool-a": "https://example.com/tool-a-1.0.0.tgz",
"tool-b": "github:owner/repo#v1.0.0",
"tool-c": "file:../tool-c"
}3Verify
Run the install again.
npm installConfirmed by docs.npmjs.com
How do I stop it coming back?
- Pick one package manager per repo and write it in the README, and commit only its lockfile.
- Run the install command from the repo root, not inside a package folder.
- Keep non-registry dependencies in the documented forms.
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