ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'Short answer
The ng command is the entry point to the Angular CLI package. This error means the package it points to is missing: the project's node_modules was never installed or is incomplete, or the global CLI install is broken. Run npm install in the project, or reinstall the CLI globally.
Fix it fast
1Find out which cause you have
Ask npm which Angular CLI the project itself has. If it is missing here, the project install is the problem; if it is present, look at the global install.
npm ls @angular/cli node --version2Match what you see, then jump to its fix
What does the error look like?
Cannot find module '@angular/cli/bin/ng'
Cause 1 of 2
The project dependencies are not installed
1Check
A workspace made with ng new lists @angular/cli as a dependency, because it holds the binary for ng commands. Without node_modules the binary is not there.
ls node_modules/@angular/cli 2>&1 | head -32Fix
Install the dependencies listed in package.json, then run the local CLI through npx, which puts locally installed bins on PATH.
npm install
npx ng version3Verify
The version banner prints.
npx ng versionConfirmed by angular.dev
Cause 2 of 2
The global Angular CLI install is broken or missing
1Check
List the globally installed packages. If @angular/cli is not listed, or the listing shows it as broken, the global ng command has nothing valid to load.
npm ls -g @angular/cli2Fix
Install the CLI again globally. On Unix-like systems a permission error can be solved with sudo, but understand the implications of running as root first.
npm install -g @angular/cli3Verify
ng runs from any folder.
ng versionConfirmed by angular.dev
How do I stop it coming back?
- Run ng through npx or an npm script so the project's own CLI version is used.
- Use a Node.js version Angular supports: it requires an active LTS or maintenance LTS release.
- Do not copy node_modules between machines; reinstall from package.json.
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
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 fixBack end
Angular build fails with SassError: Undefined variable
SassError: Undefined variable.
Sass modules loaded with @use are scoped to the file that loads them and their variables need a namespace prefix.
4 causes, each with a fix