简体   繁体   English

如何在 react 应用程序中使用 zlib? 或者什么是 zlib_binding,为什么它不见了?

[英]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.jsimport './zlib_bindings'作为其中的一行。 But there is no ./zlib_bindings.js .但是没有./zlib_bindings.js

Questions:问题:

  1. How do I fix this?我该如何解决?
  2. How does that work when I run 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.

相关问题 如何在node.js中捕获zlib错误 - How do I catch zlib errors in node.js Node.JS + Zlib + Q(承诺)-如何以糖方式更改压缩性能? - Node.JS + Zlib + Q (promises) - How do I change compression performance in a sugar way? 如何使用 zlib.gzipSync(buffer[, options]) 压缩文件,使用 zlib.gunzipSync(buffer[, options]) 解压缩文件? - How to use zlib.gzipSync(buffer[, options]) for compressing files, and zlib.gunzipSync(buffer[, options]) for decompressing files? 如何检查 base64 编码的字符串是否在 node.js 中被 zlib 压缩? - How do I check if a base64 encoded string is zlib compressed or not in node.js? 如何使用 node.js 和 zlib 解压缩 a.drawio 文件中的图表数据? - How do I decompress the diagram data in a .drawio file with node.js and zlib? 如何使用带有选项的Node.js zlib模块? - How to use Node.js zlib module with options? 为什么zlib.deflate(buf,callback)是异步的? - Why zlib.deflate(buf, callback) is async? 如何使用zlib在Node.js中使用内存泄漏来改进此代码? - How to improve this code with memory leak in nodejs with zlib? 如何解压JavaScript中zlib压缩的object? - How to decompress an object compressed by zlib in JavaScript? 我可以安全地使用哪个分隔符来分隔节点中的 zlib 压缩字符串 - which delimiter can I use safely to separate zlib deflated strings in node
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM