BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.

在这里插入图片描述

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()],
  },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

第7个前端

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值