Search code examples
javascriptreactjsnpmbabeljsbabel-preset-env

how to install babel-cli babel-preset-react


I tried all possible way to install babel-cli babel-preset-react

Things I tried npm install --save-dev babel-cli babel-preset-react

but when I check babel -h

It shows The program 'babel' can be found in the following packages:

I refer this question also but doesn't work Babel command not found


Solution

  • In order to run the babel command, you need to either install babel globaly or run it from package.json by saving it in scripts

    scripts: {
       babelCmd: "babel src/app.js --out-file=public/scripts/app.js --presets=env,react --watch"
    }
    

    and run using

    npm run babelCmd
    

    If you want to run the babel command directly, you need to install like

    npm install -g babel-cli babel-preset-react