Search code examples
node.jsangularzlibjwejose

'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?


I'm trying to use the node-jose library with angular7 for the use with JWEs. The library uses zlib as a dependency and it throws an error when compiling:

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

I opened the 'zlib.js' file and the contents are the following:

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

The problem is that the required file doesn't exist. I inspected the rest of the library and there is no such file in the whole library.

I searched the whole internet and no one has described the same problem as I have. There are some discussions regarding the 'node-jose' library but none of those issues are related to 'zlib'.

I would be extremely thankful if only someone would say they share the same error. Thanks in advance!


Solution

  • I found the answer.

    Angular isn't showing an error when compiling but shows an error in the browser. It's because the browser doesn't have 'node' libraries integrated so it can't start the 'zlib' library. Installing the 'zlib' library in 'node_modules' doesn't help since it's deprecated.

    Using the 'browserify-zlib' library and changing the ...require('browserify-zlib') in all my dependencies has fixed the issue.