问题:
ERROR in ./node_modules/http-proxy-middleware/dist/handlers/response-interceptor.js 4:13-28 Module not found: Error: Can't resolve 'zlib' in 'C:\Users\mrdxmj\Desktop\springboot+vue小框架\vue\electric-vue2\node_modules\http-proxy-middleware\dist\handlers'
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/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/views/Register.vue?vue&type=script&lang=js& 3:0-95 @ ./src/views/Register.vue?vue&type=script&lang=js& 1:0-202 1:218-221 1:223-422 1:223-422 @ ./src/views/Register.vue 2:0-60 3:0-55 3:0-55 10:2-8 @ ./src/router/index.js 5:0-45 25:13-21 @ ./src/main.js 4:0-30 21:2-8
webpack compiled with 1 error
刚遇到这个问题的时候,一头雾水,看翻译我们可以知道
错误提示:./node_modules/http-proxy-middleware代理中间件出错了;
解决问题提示:突破性更改:webpack<5用于包含节点的多边形填充。默认情况下为js核心模块。
情况已不再如此。验证您是否需要此模块,并为其配置polyfill。
如果要包含多边形填充,则需要:
-添加回退解决方案。回退:{“zlib”:require.resolve(“browserify zlib”)}
暂停“浏览zlib”
如果不想包含多边形填充,可以使用如下空模块:
决定回退:{“zlib”:false}
1. 寻找问题过程:
首先通过在网上查阅资料定位:
webpack 5更新后的版本问题;
自己是在写写接口获取后台信息时出现的错误,定位问题出在前端跨域配置出错
2. 解决问题
首先错误提示里面提供了两种解决方式,
(1)-添加回退解决方案。回退:{“zlib”:require.resolve(“browserify zlib”)}
(2)决定回退:{“zlib”:false}
第一种解决方式
(1)npm install browserify-zlib
(2) 在vue.config.js中跨域配置里面增加:
完整:
这是我昨晚遇到的问题,查阅了很多资料,但是因为修改位置不对,所以一直解决不了,以上问题总结希望对遇到跟我一样问题的小伙伴有用,第一次写博客,写的不好勿喷哈,谢谢啦!