使用Babel将ES6转换为ES5时报错解决方法

在使用rollup + babel打包ES6代码时老是报错:

resolve failed:  { Error: Cannot find module 'babel-runtime'
...

Error transforming ***.js with 'babel' plugin: It looks like your Babel configuration specifies a module transformer. Please disable it. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information


花一天的时候,终于解决了:

在.babelrc中需要进行如下配置:

 
  
{
  "presets": [
    [
      "es2015",
      {
        "modules": false
      }
    ]
  ]
}

之前的错误配置为:

{
  "presets": [ "es2015-rollup"]
}

最重要的是要加上modules为false的配置项,否则会报错: It looks like your Babel configuration specifies a module transformer. Please disable it.


你可能感兴趣的:(JavaScript)