3
votes

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.

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
@loganfsmyth can you say us more about this necessitate to use the .bin version of the package please - Webwoman

3 Answers

3
votes

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
votes

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

0
votes

npm install -g babel-cli

It works.