首页 > 解决方案 > 使用 react.lazy 时出现 NamedChunksPlugin webpack 问题

问题描述

当我尝试使用 react.lazy

const someComponent = React.lazy(() => import('COMPONENTS/ActualComponent'));

或者

const someComponent = React.lazy(() => import('../ActualComponent/index.js'));. webpack 无法加载应用程序

我相信下面的代码正在这样做,但不知道为什么。我是 webpack 的新手,我不确定为什么会这样。

```new webpack.NamedChunksPlugin((chunk) => {
  if(chunk.name) return chunk.name;

  return chunk.modules.map(
    m => path.relative(m.context, m.request)
  ).join('_');
}),```

这是我看到的错误

                           ^
TypeError: Cannot read property 'map' of undefined
    at NamedChunksPlugin.conf.plugins.webpack.NamedChunksPlugin [as nameResolver]```

Any help is appreciated! Thanks in advance !

标签: javascriptreactjswebpack

解决方案


推荐阅读