我正在做我的nodejs reactjs应用程序,突然它停止工作。我只是添加了一个代码块来执行删除请求,我的应用程序崩溃了,但我很确定它对我的代码没有任何作用。
Compiled with problems:
ERROR in ./node_modules/body-parser/lib/read.js 24:11-26
Module not found: Error: Can't resolve 'zlib' in 'C:\Users\Mateo\OneDrive\Desktop\MERN\MERN-course\client\node_modules\body-parser\lib'
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 }
字符串
以上是我的控制台中显示的许多错误之一。
我确信我的代码与此无关,因为它只是一个axios。删除请求,如果我注解代码块,错误不会消失。
有什么解决办法吗?
这是我的react版本:
"packages": {
"": {
"name": "client",
"version": "0.1.0",
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^0.27.2",
"moment": "^2.29.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-moment": "^1.1.2",
"react-redux": "^8.0.4",
"react-router-dom": "^6.4.1",
"react-scripts": "5.0.1",
"redux": "^4.2.0",
"redux-devtools-extension": "^2.13.9",
"redux-thunk": "^2.4.1",
"uuid": "^9.0.0",
"web-vitals": "^2.1.4"
}
型
我的节点版本
"scripts": {
"start": "node server",
"server": "nodemon server",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
"author": "Mateo Ghidini",
"license": "MIT",
"dependencies": {
"axios": "^0.27.2",
"bcryptjs": "^2.4.3",
"config": "^3.3.7",
"express": "^4.18.1",
"express-validator": "^6.14.2",
"gravatar": "^1.8.2",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.5.4",
"request": "^2.88.2"
},
"devDependencies": {
"assert": "^2.0.0",
"buffer": "^6.0.3",
"concurrently": "^7.3.0",
"crypto-browserify": "^3.12.0",
"https-browserify": "^1.0.0",
"nodemon": "^2.0.19",
"os-browserify": "^0.3.0",
"process": "^0.11.10",
"react-app-rewired": "^2.2.1",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"url": "^0.11.0"
}
型
1条答案
按热度按时间6psbrbz91#
Webpack 5有一系列突破性的变化,就像任何主要版本一样。
所以你必须按照错误消息的提示去做,配置webpack为每个节点核心模块使用polyfill(它建议polyfill webpack 4使用),并安装polyfill。当然,你不能改变react-scripts webpack的配置,所以你被卡住了。
https://github.com/facebook/create-react-app/issues/12072#issuecomment-1074566504