3

I had installed babel-cli globally using npm. And I had a script.js file which contains the ES6 code. When I tried to compile that using $babel script.js -o out.js, it just copy all the contains of the script.js to out.js.

As far I concern, it should convert all the ES6 code to ES5.

Even if I run the script.js file without any content, it should show "use strict"; in my out.js. But it shows an empty file. Unable to figure out whats wrong?

Moreover I am unable to understand why "https://www.npmjs.com/package/babel-cli" says to install babel-cli globally where as "https://babeljs.io/docs/setup/#babel_cli" says to install that locally.

When I installed babel-cli locally and try to compile the script.js file it simply shows

'babel' is not recognized as an internal or external command, operable program or batch file.

  • 1
    Possible duplicate of [Babel file is copied without being transformed](http://stackoverflow.com/questions/33440405/babel-file-is-copied-without-being-transformed) – loganfsmyth Feb 06 '16 at 21:59
  • 3
    This is kind of two questions. The first is a dup, and the second is just that when you install locally, you need to run the local version using `./node_modules/.bin/babel`. – loganfsmyth Feb 06 '16 at 22:01
  • @loganfsmyth can you say us more about this necessitate to use the .bin version of the package please – Webwoman Sep 28 '18 at 16:46

3 Answers3

3

This should answer your question worked for me. https://github.com/babel/babel/issues/4066

or install babel-cli globally and try it works then.

1

First Go to main directory or open new terminal

step 1: go to main directory

open terminal or (type cd so that you can directly switch in main directory)

step 2 : npm install -g babel-cli

now successfully install babel cli in your machine

Neel Patel
  • 2,028
  • 18
  • 17
0

npm install -g babel-cli

It works.