问题描述
我想使用 Webpack 的 React Loadable 在 ReactJs 中实现 SSR。以下是 package.json 文件中的几行:
const { ReactLoadablePlugin } = require('react-loadable/webpack');
plugins:[
new ReactLoadablePlugin({
filename: path.resolve(__dirname,'dist','react-loadable.json')
}),]
但我收到以下错误:
> [webpack-cli] TypeError: compiler.plugin is not a function
at ReactLoadablePlugin.apply
我该如何解决?
解决方法
我有同样的错误,但使用 webpack-shell-plugin NodeJs 中使用 Webpack 5 的依赖项,所以我的解决方法是删除 webpack-shell-plugin 并添加 webpack-shell-plugin-next :
npm install --save-dev webpack-shell-plugin-next
webpack.config.js 文件:
const WebpackShellPluginNext = require('webpack-shell-plugin-next');
module.exports = {
...
plugins: [
new WebpackShellPluginNext({
onBuildStart:{
scripts: ['echo "===> Starting packing with WEBPACK 5"'],blocking: true,parallel: false
},onBuildEnd:{
scripts: ['npm run yourCommand'],blocking: false,parallel: true
}
})
]
}
我希望此修复程序可以帮助您或可以帮助某人。
,问题很可能是您尝试在 Webpack 5 中使用 Webpack 4 插件,只是 Webpack 有无信息的错误消息。尝试升级 ReactLoadablePlugin。