我的页面工作正常,但在编译我的反应代码时突然发生了这个错误
Compiled with problems:
ERROR in ./node_modules/body-parser/lib/read.js 20:11-26
Module not found: Error: Can't resolve 'zlib' in 'D:\BooksGalore app\frontend\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 }
ERROR in ./node_modules/content-disposition/index.js 19:15-39
Module not found: Error: Can't resolve 'path' in 'D:\BooksGalore app\frontend\node_modules\content-disposition'
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 }
ERROR in ./node_modules/destroy/index.js 12:17-41
Module not found: Error: Can't resolve 'fs' in 'D:\BooksGalore app\frontend\node_modules\destroy'
ERROR in ./node_modules/etag/index.js 20:12-31
Module not found: Error: Can't resolve 'fs' in 'D:\BooksGalore app\frontend\node_modules\etag'
ERROR in ./node_modules/express/lib/application.js 42:14-37
Module not found: Error: Can't resolve 'path' in 'D:\BooksGalore app\frontend\node_modules\express\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: { "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 }
ERROR in ./node_modules/express/lib/request.js 18:11-30
Module not found: Error: Can't resolve 'net' in 'D:\BooksGalore app\frontend\node_modules\express\lib'
ERROR in ./node_modules/express/lib/response.js 29:11-26
Module not found: Error: Can't resolve 'path' in 'D:\BooksGalore app\frontend\node_modules\express\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: { "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 }
ERROR in ./node_modules/express/lib/view.js 16:11-26
Module not found: Error: Can't resolve 'path' in 'D:\BooksGalore app\frontend\node_modules\express\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: { "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 }
ERROR in ./node_modules/express/lib/view.js 18:9-22
Module not found: Error: Can't resolve 'fs' in 'D:\BooksGalore app\frontend\node_modules\express\lib'
ERROR in ./node_modules/mime-types/index.js 15:14-37
Module not found: Error: Can't resolve 'path' in 'D:\BooksGalore app\frontend\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 }
ERROR in ./node_modules/mime/mime.js 1:11-26
Module not found: Error: Can't resolve 'path' in 'D:\BooksGalore app\frontend\node_modules\mime'
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 }
ERROR in ./node_modules/mime/mime.js 3:9-22
Module not found: Error: Can't resolve 'fs' in 'D:\BooksGalore app\frontend\node_modules\mime'
ERROR in ./node_modules/send/index.js 29:9-22
Module not found: Error: Can't resolve 'fs' in 'D:\BooksGalore app\frontend\node_modules\send'
ERROR in ./node_modules/send/index.js 39:11-26
Module not found: Error: Can't resolve 'path' in 'D:\BooksGalore app\frontend\node_modules\send'
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 }
ERROR in ./node_modules/serve-static/index.js 20:14-37
Module not found: Error: Can't resolve 'path' in 'D:\BooksGalore app\frontend\node_modules\serve-static'
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 }
Compiled with problems:
ERROR in ./node_modules/body-parser/lib/read.js 20:11-26
Module not found: Error: Can't resolve 'zlib' in 'D:\BooksGalore app\frontend\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 }
ERROR in ./node_modules/content-disposition/index.js 19:15-39
Module not found: Error: Can't resolve 'path' in 'D:\BooksGalore app\frontend\node_modules\content-disposition'
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 }
ERROR in ./node_modules/destroy/index.js 12:17-41
Module not found: Error: Can't resolve 'fs' in 'D:\BooksGalore app\frontend\node_modules\destroy'
ERROR in ./node_modules/etag/index.js 20:12-31
Module not found: Error: Can't resolve 'fs' in 'D:\BooksGalore app\frontend\node_modules\etag'
ERROR in ./node_modules/express/lib/application.js 42:14-37
Module not found: Error: Can't resolve 'path' in 'D:\BooksGalore app\frontend\node_modules\express\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: { "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 }
ERROR in ./node_modules/express/lib/request.js 18:11-30
Module not found: Error: Can't resolve 'net' in 'D:\BooksGalore app\frontend\node_modules\express\lib'
ERROR in ./node_modules/express/lib/response.js 29:11-26
Module not found: Error: Can't resolve 'path' in 'D:\BooksGalore app\frontend\node_modules\express\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: { "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 }
ERROR in ./node_modules/express/lib/view.js 16:11-26
Module not found: Error: Can't resolve 'path' in 'D:\BooksGalore app\frontend\node_modules\express\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: { "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 }
ERROR in ./node_modules/express/lib/view.js 18:9-22
Module not found: Error: Can't resolve 'fs' in 'D:\BooksGalore app\frontend\node_modules\express\lib'
ERROR in ./node_modules/mime-types/index.js 15:14-37
Module not found: Error: Can't resolve 'path' in 'D:\BooksGalore app\frontend\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 }
ERROR in ./node_modules/mime/mime.js 1:11-26
Module not found: Error: Can't resolve 'path' in 'D:\BooksGalore app\frontend\node_modules\mime'
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 }
ERROR in ./node_modules/mime/mime.js 3:9-22
Module not found: Error: Can't resolve 'fs' in 'D:\BooksGalore app\frontend\node_modules\mime'
ERROR in ./node_modules/send/index.js 29:9-22
Module not found: Error: Can't resolve 'fs' in 'D:\BooksGalore app\frontend\node_modules\send'
ERROR in ./node_modules/send/index.js 39:11-26
Module not found: Error: Can't resolve 'path' in 'D:\BooksGalore app\frontend\node_modules\send'
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 }
ERROR in ./node_modules/serve-static/index.js 20:14-37
Module not found: Error: Can't resolve 'path' in 'D:\BooksGalore app\frontend\node_modules\serve-static'
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 }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我遇到这个问题已经有一段时间了,直到我从过去的提交中创建了一个新分支。
后来,经过对代码的大量研究和审查,我意识到我是从“@express”而不是“@angular/router”导入 Router 类。
ts 文件导入中导致上述错误的代码行如下所示;
下面的代码是解决方案。
注意: Router 类是提供视图之间导航和 URL 操作功能的服务。
I experienced this issue for some time to a point I created a new branch from some past commit.
Later after much research and review on my code I realized I was importing Router class from '@express' instead of '@angular/router'.
The line of code in ts file import which led to errors above is shown below;
The code below is the solution.
NB: Router class is service that provides navigation among views and URL manipulation capabilities.
我在使用 React 并尝试在屏幕上显示 json 响应时遇到了此错误。由于我使用了“响应”,它会自动从express导入响应(我相信),这导致了错误。我所要做的就是删除组件中的响应导入,然后它就消失了。
I encountered this error when using React and trying to display my json response to the screen. Since I used 'response', it auto imported response from express (I believe), which caused the errors. All I had to do was delete that response import in my component and it went away.
删除代码中响应的导入
Remove the imports of the response in your code
您的节点模块中缺少 zlib 软件包,请尝试再次安装该软件包或尝试删除节点模块并使用
npm install
安装软件包。zlib package is missing in your node modules, try installing the package again or try removing node modules and install the packages using
npm install
.所以事实证明 VS Code 会随机放入这样一个无用的导入:
我实际上不知道它为什么这样做。但删除额外的导入可以解决这个问题。该错误非常令人生畏并且难以调试。特别是如果它是随机发生的并且您只是使用标准的反应应用程序。
我建议查看您最近修改过的文件,以查找任何不熟悉的额外导入。删除那些。应该修复它。
So turns out VS Code will randomly put a useless import like this in:
I actually have no idea why it does this. But removing the extra import fixes it. The error is quite intimidating and difficult to debug. Especially if it occurs randomly and you are just working with a standard react app.
I would suggest looking into recent files that you've modified for any extra imports that are unfamiliar. Remove those. Should fix it.
我以前遇到过这个问题,只需删除下面的代码行
import { json } from "body-parser";
一切都会好的:)
I've faced this problem before, just remove the line of code below
import { json } from "body-parser";
and everything will be OK :)
从代码中删除以下行
Remove the below line from the code