項(xiàng)目升級webpack5后報(bào)錯(cuò):process is not defined
原因:webpack5不再自動 polyfill Node.js 的核心模塊找筝,意味著如果你在瀏覽器或類似的環(huán)境中運(yùn)行的代碼中使用它們懦铺,你必須從 NPM 中安裝兼容的模塊般甲,并自己包含它們webpack官方說明
安裝process依賴npm i --save-dev process
Webpack 5 - Uncaught ReferenceError: process is not defined
網(wǎng)上找了兩種方案:
配置resolve我的項(xiàng)目不管用
resolve: {
alias: {
process: "process/browser"
} 就乓,
fallback: { ..., process: require.resolve('process/browser')...}
}
配置plugin 親測管用
module.exports = {
...
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser',
}),
],
}