原先安装的包是:babel-core和babel-loader
babel-plugin-transform-runtime
babel-preset-env和babel-preset-stage-0
然后就报了这个错误:requires a peer of @babel/core@^7.0.0 but none was installed
这是由于babel-core版本不对应产生的
随后卸掉babel-core 安装@babel/core
又报了个错误:Error: Plugin/Preset files are not allowed to export objects, only functions.
原因是在新版本babel中依赖的名字也变了
随后卸了 babel-plugin-transform-runtime 安装@babel/plugin-transform-runtime
再卸了babel-preset-env和babel-preset-stage-0 安装@babel/preset-env和@babel/preset-stage-0
然后又报了个As of v7.0.0-beta.55, we've removed Babel's Stage presets.
原因是在7.x的babel中 进行了一些更新和变动 @babel/preset-stage-0不再使用了
于是卸了@babel/preset-stage-0
又报了个错误:Support for the experimental syntax 'classProperties' isn't currently enabled
原因是缺少指定的插件
随后安装@babel/plugin-proposal-class-properties
最终的配置文件.babelrc:
{
"presets": ["@babel/preset-env"],
"plugins": ["@babel/plugin-transform-runtime","@babel/plugin-proposal-class-properties"]
}
经历了四次波折 终于解决了: