问题记录
关于 webpack 5 引入 node 内置模块报错
问题:部分依赖包中 node
内置模块引起报错
txt
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
1
2
2
解决:
- 使用插件
js
const { defineConfig } = require('@vue/cli-service')
const NodePolyfill = require('node-polyfill-webpack-plugin')
module.exports = defineConfig({
configureWebpack: config => {
config.plugins?.push(new NodePolyfill())
},
})
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
- 按照错误提示配置
js
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
configureWebpack: config => {
config.resolve.fallback = {
// want to include a polyfill
path: require.resolve('path-browserify'),
// don't want to include a polyfill
http: false
}
},
})
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12