错误如下所示:
ERROR Failed to compile with 1 error 下午11:40:17
error in ./src/components/ProductParam.vue?vue&type=script&lang=js&
Module not found: Error: Can't resolve 'process' in 'E:\mooc\vueMallsystem\mimall\src\components'
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: { "process": require.resolve("process/browser") }'
- install 'process'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "process": false }
检查下来是因为 webpack 5 以前的版本包含 polyfills。错误信息也给出了这个原因。
解决办法:
安装依赖
npm install path-browserify
vue.config.js中配置
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")
configureWebpack: {
resolve: {
fallback: {
fs: false,
crypto: require.resolve("crypto-browserify")
}
},
plugins: [new NodePolyfillPlugin()],
},