1:报错
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.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "timers": require.resolve("timers-browserify") }'
- install 'timers-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "timers": false }
2.解决方案:使用 node-polyfill-webpack-plugin
+ const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")
vue.config.js
configureWebpack: {
plugins: [
new NodePolyfillPlugin(),
],
},
3.原因:webpack5
不再自动添加node 模块的polyfill,如果我们用了就要自行处理了。