Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

The shell says babel: command not found

Errorbabel: command not found

Short 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.

  • Applies to Babel 8, npm 10, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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/core
  2. 2Match what you see, then jump to its fix

    1. 1ls: node_modules/.bin/babel: No such file or directory@babel/cli is not installed in the projectFix
    2. 2The 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. 3npx babel runs, but behaves like Babel 6 and rejects modern syntax or config.npx pulled an old Babel because nothing was installed firstFix

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/core

2Fix

Install both as dev dependencies in the folder that has your package.json.

npm install --save-dev @babel/core @babel/cli

3Verify

The binary exists after the install.

ls node_modules/.bin/babel

Confirmed by babeljs.io

Did this fix it?

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_modules

2Fix

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 build

3Verify

Babel prints no 'not found' and writes the output folder.

ls lib

Confirmed by docs.npmjs.com

Did this fix it?

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 --version

2Fix

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 --version

3Verify

The reported version matches what npm ls shows.

npm ls @babel/cli

Confirmed by babeljs.io

Did this fix it?

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 fix

Back 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.