[英]How do I use zlib in a react app? or what is zlib_binding and why is it missing?
I have created a brand new react app using VS2022 and create-react-app.我使用 VS2022 和 create-react-app 创建了一个全新的 react 应用程序。
I have installed zlib
using npm install zlib
.我已经使用
npm install zlib
zlib
getting the following error when running npm run start
:运行
npm run start
时出现以下错误:
ERROR in ./node_modules/zlib/lib/zlib.js 1:0-43
Module not found: Error: Can't resolve './zlib_bindings' in 'c:\projects\mall\mall\node_modules\zlib\lib'
To troubleshoot, I created a test.js
file with just require('zlib')
in it and it works.为了排除故障,我创建了一个
test.js
文件,其中只包含require('zlib')
并且它可以工作。
file ./node_modules/zlib/lib/zlib.js
has import './zlib_bindings'
as a single line in it.文件
./node_modules/zlib/lib/zlib.js
有import './zlib_bindings'
作为其中的一行。 But there is no ./zlib_bindings.js
.但是没有
./zlib_bindings.js
。
Questions:问题:
node test.js
?node test.js
时,它是如何工作的?Your test.js
file works because you run it with node.您的
test.js
文件有效,因为您使用节点运行它。
The zlib module provides compression functionality implemented using Gzip and Deflate/Inflate.
zlib 模块提供使用 Gzip 和 Deflate/Inflate 实现的压缩功能。 It is the part of nodejs core module written in c++
它是用c ++编写的nodejs核心模块的一部分
This module can't be used outside of node.js此模块不能在 node.js 之外使用
You can however try to use react-zlib-js
and it should work!但是,您可以尝试使用
react-zlib-js
,它应该可以工作!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.