'node-jose' 库正在使用 'zlib' 库作为引发错误的依赖项。我该如何解决它,您遇到过同样的问题吗?

'node-jose' library is using 'zlib' library as a dependency which throws an error. How do I fix it and have you encountered the same problem?

我正在尝试使用 node-jose library with angular7 for the use with JWEs. The library uses zlib 作为依赖项,但它在编译时抛出错误:

ERROR in ./node_modules/zlib/lib/zlib.js
Module not found: Error: Can't resolve './zlib_bindings' in '~\WebApp\node_modules\zlib\lib'

我打开了'zlib.js'文件,内容如下:

module.exports = require('./zlib_bindings');

问题是所需的文件不存在。我检查了图书馆的其余部分,整个图书馆都没有这样的文件。

我搜索了整个互联网,没有人描述过和我一样的问题。有一些关于 'node-jose' 库的讨论,但其中 none 与 'zlib'.

有关

如果有人说他们有同样的错误,我将非常感激。提前致谢!

我找到了答案。

Angular 在编译时不显示错误,但在浏览器中显示错误。这是因为浏览器没有集成'node'库,所以无法启动'zlib'库。在 'node_modules' 中安装 'zlib' 库没有帮助,因为它已被弃用。

使用 'browserify-zlib' 库并更改我所有依赖项中的 ...require('browserify-zlib') 已解决此问题。

此 PR 将修复 node-jose 中的问题

https://github.com/cisco/node-jose/pull/264

这作为 node-jose-browserifyhttps://www.npmjs.com/package/node-jose-browserify

发布到 npm
npm i node-jose-browserify