通过npm安装babel时输出下面的错误
zhouruibin@Litter-bear:~/Desktop$ sudo npm install -g babel
/usr/local/bin/babel -> /usr/local/lib/node_modules/babel/cli.js
/usr/local/bin/babel-node -> /usr/local/lib/node_modules/babel/cli.js
/usr/local/bin/babel-external-helpers -> /usr/local/lib/node_modules/babel/cli.js
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/npmconf requires once@'~1.1.1' but will load
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/once,
npm WARN unmet dependency which is version 1.3.2
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/npmconf requires mkdirp@'~0.3.3' but will load
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/mkdirp,
npm WARN unmet dependency which is version 0.5.1
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/npmconf requires osenv@'0.0.3' but will load
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/osenv,
npm WARN unmet dependency which is version 0.1.3
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/npmconf requires nopt@'2' but will load
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/nopt,
npm WARN unmet dependency which is version 3.0.4
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/npmconf requires semver@'2' but will load
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/semver,
npm WARN unmet dependency which is version 5.0.3
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/npmconf requires ini@'~1.1.0' but will load
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/ini,
npm WARN unmet dependency which is version 1.3.4
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/read-package-json/node_modules/normalize-package-data requires semver@'2' but will load
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/semver,
npm WARN unmet dependency which is version 5.0.3
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/read-package-json/node_modules/normalize-package-data requires github-url-from-git@'~1.1.1' but will load
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/github-url-from-git,
npm WARN unmet dependency which is version 1.4.0
babel@6.0.12 /usr/local/lib/node_modules/babel
zhouruibin@Litter-bear:~/Desktop$ babel
/usr/local/bin/babel: line 3: syntax error near unexpected token `"The CLI has been moved into the package `babel-cli`."'
/usr/local/bin/babel: line 3: `console.error("The CLI has been moved into the package `babel-cli`.");'
从这篇文章上的步骤来的http://www.codefrom.com/paper/Babel.js%E6%8F%92%E4%BB%B6%E5%BC%80%E5%8F%91%E4%B9%8B%E4%B8%80%20-%20Babel%E4%B8%8EAST
我也用了官网https://babeljs.io/docs/usage/cli/里的步骤,用npm install --global babel-cli,在命令行里babel命令能行得通,但我在转换时就根本没有把ES6的转成ES5的,只是原文输出而已,我用babel提供的在线转换http://babeljs.io/repl对比了下,完全不一致的!!!
谁能告诉我问题是怎么了???
测试转换的代码如下(ES6):
//类的定义
class Animal {
//ES6中新型构造器
constructor(name) {
this.name = name;
}
//实例方法
sayName() {
console.log('My name is '+this.name);
}
}
//类的继承
class Programmer extends Animal {
constructor(name) {
//直接调用父类构造器进行初始化
super(name);
}
program() {
console.log("I'm coding...");
}
}
//测试我们的类
var animal=new Animal('dummy'),
wayou=new Programmer('wayou');
animal.sayName();//输出 ‘My name is dummy’
wayou.sayName();//输出 ‘My name is wayou’
wayou.program();//输出 ‘I'm coding...’
迷茫2017-04-17 13:24:46
you need uninstall
npm uninstall babel --save-dev
and then
npm install babel-loader babel-core --save-dev