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: { "zlib": require.resolve("browserify-zlib") }'
- install 'browserify-zlib'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "zlib": false }
@ ./node_modules/body-parser/lib/read.js 14:14-32
@ ./node_modules/body-parser/lib/types/text.js 19:11-29
@ ./node_modules/body-parser/index.js 142:15-42
@ ./node_modules/babel-loader/lib/index.js??clonedRuleSet-40[0].rules[0].use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/views/Login/Index.vue?vue&type=script&lang=js& 33:0-35
@ ./src/views/Login/Index.vue?vue&type=script&lang=js& 1:0-217 1:233-236 1:238-452 1:238-452
@ ./src/views/Login/Index.vue 2:0-57 3:0-52 3:0-52 10:2-8
@ ./src/router/index.js 4:0-40 35:13-18
@ ./src/router/index.js 4:0-40 35:13-18
@ ./src/main.js 7:0-30 19:0-17 41:10-16
ERROR in ./node_modules/mime-types/index.js 25:14-37
Module not found: Error: Can't resolve 'path' in 'D:\vue\vuepro\node_modules\mime-types'
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: { "path": require.resolve("path-browserify") }'
- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "path": false }
@ ./node_modules/type-is/index.js 21:11-32
@ ./node_modules/body-parser/lib/types/text.js 21:13-31
@ ./node_modules/body-parser/index.js 142:15-42
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: { "path": require.resolve("path-browserify") }'
- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "path": false }
@ ./node_modules/type-is/index.js 21:11-32
@ ./node_modules/body-parser/lib/types/text.js 21:13-31
@ ./node_modules/body-parser/index.js 142:15-42
- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "path": false }
@ ./node_modules/type-is/index.js 21:11-32
@ ./node_modules/body-parser/lib/types/text.js 21:13-31
@ ./node_modules/body-parser/index.js 142:15-42
@ ./node_modules/babel-loader/lib/index.js??clonedRuleSet-40[0].rules[0].use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/views/Login/Index.vue?vue&type=script&lang=js& 33:0-35
@ ./src/views/Login/Index.vue?vue&type=script&lang=js& 1:0-217 1:233-236 1:238-452 1:238-452
@ ./src/views/Login/Index.vue 2:0-57 3:0-52 3:0-52 10:2-8
@ ./src/router/index.js 4:0-40 35:13-18
@ ./src/main.js 7:0-30 19:0-17 41:10-16
webpack compiled with 6 errors
检查下来是因为 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()],
},