我已将webpack从2.5.1升级到3.6。在webpack开发服务器模式下一切顺利但在webpack构建中失败。我观察到以下错误。
ERROR in chunk main [entry]
[name].[chunkhash].js
'import' and 'export' may only appear at the top level (42:6)
| if (false) {
| module.hot.accept('./reducers', function () {
| import('./reducers').then(function (reducerModule) {
| var createReducers = reducerModule.default;
| var nextReducers = createReducers(store.asyncReducers);
什么会触发错误?我已经正确设置了babel loader,它可以在2.5 webpack版本中正常工作。
更新:如果我删除new webpack.optimize.ModuleConcatenationPlugin()
我没有收到该错误。看起来像块文件有es6代码,而babel-parser没有解析。我如何配置webpack以使其工作?
答案 0 :(得分:0)
您可以导入顶级
import reducers from './reducers'
if (false) {
module.hot.accept('./reducers', function () {
reducers.then(function (reducerModule) {
var createReducers = reducerModule.default;
var nextReducers = createReducers(store.asyncReducers);
或
if (false) {
module.hot.accept('./reducers', function () {
require('./reducers').default.then(function (reducerModule) {
var createReducers = reducerModule.default;
var nextReducers = createReducers(store.asyncReducers);