nodejs+react使用webpack打包时控制台报错

时间:2023-03-10 03:34:02
nodejs+react使用webpack打包时控制台报错

一、错误:Uncaught ReferenceError: process is not defined

  解决方法:

new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
})

  在webpack.config.js文件中的plugins中加入上述代码

二、错误: fixes WARNING Critical dependency: the request of a dependency is an expression

  解决方法:

new webpack.ContextReplacementPlugin(
/(.+)?express(\\|\/)(.+)?/,
path.join(__dirname, 'src'),
{}
)

  在webpack.config.js文件中的plugins中加入上述代码