The shell says babel: command not found
babel: command not foundShort answer
The shell finds babel only if its folder is on PATH. Babel is meant to be installed per project as @babel/cli, and its binary sits in node_modules/.bin, which npm adds to PATH only inside npm scripts. Install @babel/core and @babel/cli, then call it with npx or an npm script.
Fix it fast
1Find out which cause you have
Check whether the Babel binary exists in this project at all.
ls node_modules/.bin/babel npm ls @babel/cli @babel/core2Match what you see, then jump to its fix
- 1
ls: node_modules/.bin/babel: No such file or directory@babel/cli is not installed in the projectFix - 2
The package is installed, yet the bare command still fails in the terminal.babel is typed in the shell, but only project binaries hold itFix - 3
npx babel runs, but behaves like Babel 6 and rejects modern syntax or config.npx pulled an old Babel because nothing was installed firstFix
- 1
What does the error look like?
babel: command not found
Cause 1 of 3
@babel/cli is not installed in the project
1Check
The Babel docs say to install @babel/core and @babel/cli as dev dependencies. Without them there is no binary to find.
npm ls @babel/cli @babel/core2Fix
Install both as dev dependencies in the folder that has your package.json.
npm install --save-dev @babel/core @babel/cli3Verify
The binary exists after the install.
ls node_modules/.bin/babelConfirmed by babeljs.io
Cause 2 of 3
babel is typed in the shell, but only project binaries hold it
1Check
Installing locally puts the binary in node_modules/.bin. A normal shell does not search that folder; npm run does, because it adds node_modules/.bin to the PATH for the scripts it runs.
echo $PATH | tr ':' '\n' | grep node_modules2Fix
Call the binary through npx, by its relative path, or from a script in package.json.
npx babel src --out-dir lib
./node_modules/.bin/babel src --out-dir lib
# package.json
"scripts": { "build": "babel src --out-dir lib" }
# then
npm run build3Verify
Babel prints no 'not found' and writes the output folder.
ls libConfirmed by docs.npmjs.com
Cause 3 of 3
npx pulled an old Babel because nothing was installed first
1Check
The Babel docs warn that running npx babel before installing @babel/cli and @babel/core makes npx fetch out-of-date Babel 6.x. A package.json should exist too.
npx babel --version2Fix
Create package.json if missing, install the two packages, then rerun npx babel.
npm init -y
npm install --save-dev @babel/core @babel/cli
npx babel --version3Verify
The reported version matches what npm ls shows.
npm ls @babel/cliConfirmed by babeljs.io
How do I stop it coming back?
- Install Babel per project, not globally, as the Babel docs recommend, so every machine uses the same version.
- Put the command in an npm script so teammates and CI do not need to know where the binary lives.
- Commit package.json and the lockfile so a fresh clone installs the same Babel.
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