webpack4.x配置babel build失败, 报错Unknown substitution "BODY" given

webpack.config.js 中配置babel-loader

{
    exclude: /node_modules/,
    test: /\.(js)$/,
    loader: 'babel-loader'
}

.babelrc 配置使用babel-preset-env进行转码

{
  "presets": ["env"]
}

babel-core也安装了

在build的时候报错了

    ERROR in ./src/core/index.js
Module build failed (from ./node_modules/_babel-loader@8.0.2@babel-loader/lib/index.js):
Error: Unknown substitution "BODY" given
    at Object.keys.forEach.key (E:\global\develop\visitor-next\node_modules\_@babel_template@7.0.0@@babel\template\lib\populate.js:35:15)
    at Array.forEach (<anonymous>)
    at populatePlaceholders (E:\global\develop\visitor-next\node_modules\_@babel_template@7.0.0@@babel\template\lib\populate.js:33:31)
    at arg (E:\global\develop\visitor-next\node_modules\_@babel_template@7.0.0@@babel\template\lib\string.js:22:51)
    at arg (E:\global\develop\visitor-next\node_modules\_@babel_template@7.0.0@@babel\template\lib\builder.js:77:14)
    at spec (E:\global\develop\visitor-next\node_modules\_babel-plugin-transform-es2015-for-of@6.23.0@babel-plugin-transform-es2015-for-of\lib\index.js:171:20)

请大神赐教,是少了什么插件吗?

阅读 7.1k
2 个回答

babel-core安装了吗

感谢大家,已经找到答案了, 安装babel-loader@8版本的话, core和preset-env需要7版本以上才行

clipboard.png需要安装图中的两个

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题