node.js - npm安装babel出错

 我是雅婷姑娘 发布于 2022-11-06 16:53

通过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...’
6 个回答
  • 太感谢了。就是需要卸掉 babel 安装 babel-cli 谢谢喵咪大大的答案

    2022-11-11 19:20 回答
  • you need uninstall

    npm uninstall babel --save-dev

    and then

    npm install babel-loader babel-core --save-dev

    2022-11-11 19:34 回答
  • 把node还有后面装的一大堆所有的东西都升到最新版本

    2022-11-11 19:45 回答
  • 我也是,安装后编译了根本没转成ES5

    2022-11-11 19:51 回答
  • 你这个问题解决了吗?我也遇到跟你一样的问题了

    2022-11-11 20:08 回答
  • 新版本babel,拆分成babel-cli和babel-core,你2个都要install。

    2022-11-11 20:14 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有