auth0 / node-jsonwebtoken

JsonWebToken implementation for node.js http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html
MIT License
17.63k stars 1.22k forks source link

util.inherits is not a function #825

Open ralyodio opened 2 years ago

ralyodio commented 2 years ago

Getting this error in sveltekit:

500

util.inherits is not a function

node_modules/jws/lib/data-stream.js@http://localhost:3000/node_modules/.vite/deps/jsonwebtoken.js?v=0b51d446:77:10
__require2@http://localhost:3000/node_modules/.vite/deps/chunk-EVPD4D7C.js?v=0b51d446:47:50
node_modules/jws/lib/sign-stream.js@http://localhost:3000/node_modules/.vite/deps/jsonwebtoken.js?v=0b51d446:535:22
__require2@http://localhost:3000/node_modules/.vite/deps/chunk-EVPD4D7C.js?v=0b51d446:47:50
node_modules/jws/index.js@http://localhost:3000/node_modules/.vite/deps/jsonwebtoken.js?v=0b51d446:718:22
__require2@http://localhost:3000/node_modules/.vite/deps/chunk-EVPD4D7C.js?v=0b51d446:47:50
node_modules/jsonwebtoken/decode.js@http://localhost:3000/node_modules/.vite/deps/jsonwebtoken.js?v=0b51d446:753:15
__require2@http://localhost:3000/node_modules/.vite/deps/chunk-EVPD4D7C.js?v=0b51d446:47:50
node_modules/jsonwebtoken/index.js@http://localhost:3000/node_modules/.vite/deps/jsonwebtoken.js?v=0b51d446:2845:15
__require2@http://localhost:3000/node_modules/.vite/deps/chunk-EVPD4D7C.js?v=0b51d446:47:50
@http://localhost:3000/node_modules/.vite/deps/jsonwebtoken.js?v=0b51d446:2858:28
townsean commented 2 years ago

I ran into this issue I got a fix for it. I had to config Vite to add a polyfill for the util module.

From a comment on a different GitHub issue, I learned builtin node modules aren't polyfilled by default with Vite so you'll need to manually add them. This Medium article was useful in figuring out how to do that.

ralyodio commented 2 years ago

yeah i tried that. it fixed that issue but not Buffer. It works in static build but not dev now. Dev says buffer is imported twice. I gave up and did a signing server on the backend.

BasilaryGroup commented 1 year ago

There is a very simple work around, use https://github.com/panva/jose

It look less than 2 minutes to install and modify my code.

cryptominnow commented 1 year ago

I ran into this issue I got a fix for it. I had to config Vite to add a polyfill for the util module.

From a comment on a different GitHub issue, I learned builtin node modules aren't polyfilled by default with Vite so you'll need to manually add them. This Medium article was useful in figuring out how to do that.

vite-plugin-node-polyfills appears to be a better modern solution for vite users

Alan-Graton commented 2 days ago

I ran into this issue I got a fix for it. I had to config Vite to add a polyfill for the util module.

From a comment on a different GitHub issue, I learned builtin node modules aren't polyfilled by default with Vite so you'll need to manually add them. This Medium article was useful in figuring out how to do that.

You saved me dude, thank you very much ^-^