2

I want to transpile several js files that are in ES6 to be compatible with chrome, but it seems the docs in http://babeljs.io/docs/usage/cli/ are not accurate.

After doing the first few steps I type in the console: babel and get:

You have mistakenly installed the babel package, which is a no-op in Babel 6. Babel's CLI commands have been moved from the babel package to the babel-cli package.

npm uninstall babel
npm install --save-dev babel-cli

See http://babeljs.io/docs/usage/cli/ for setup instructions.

And even if I run those two commands it mention, I still get the same error.

So my question is how are you supposed to transpile files with Babel and CLI?

shinzou
  • 5,850
  • 10
  • 60
  • 124
  • 1
    Probably you have babel installed globally, perform `npm uninstall babel -g` (may require sudo) – Andrey Mar 01 '17 at 15:03
  • I guess it was installed globally, but now I get: `'babel' is not recognized as an internal or external command, operable program or batch file.` after rerunning `npm install --save-dev babel-cli` @Andrey – shinzou Mar 01 '17 at 15:07
  • 1
    *"So my question is how are you supposed to transpile files with Babel and CLI?"* Often you create a script in the `package.json`, e.g. `"scripts": { "build": "babel ... "}` and run `npm run build`. – Felix Kling Mar 01 '17 at 15:24
  • @FelixKling yes I realize that but I have no idea how to configure babel and webpack with the code I have and their sites aren't very helpful with that. – shinzou Mar 01 '17 at 15:26
  • Are you on windows OS? – Andrey Mar 01 '17 at 15:33
  • in your project root as cwd try `./node_modules/.bin/babel-cli --whatever-args` – Daniel Lizik Mar 01 '17 at 16:58
  • @Andrey yes, win 10. – shinzou Mar 02 '17 at 07:30
  • Doesn't work... no babel-cli in .bin even after I did `npm install --save-dev babel-cli` @Daniel_L – shinzou Mar 02 '17 at 07:34
  • In Windows, it's a problem to run the local module as binary. You can access local babel as `node_modules\.bin\babel someFile.js`. Maybe this can help http://stackoverflow.com/questions/9679932/how-to-use-package-installed-locally-in-node-modules – Andrey Mar 02 '17 at 08:49

1 Answers1

3

A bit old question, but in case someone ended here through Google like me:

I had the same problem, just ran

npm install --save-dev babel-cli

in a new and completely empty directory in order to test something and could not transpile when calling babel through npx with the same error. I didn't have Babel installed globally, but after a while I noticed npm didn't create the package.json file. So I deleted everything, created empty package.json with just

{

}

installed babel-cli again (npm now added dev dependency to the json file) and now it works fine.

bulhi
  • 41
  • 5