Module not found: Can't resolve imported dependency "crypto" when using jsonwebtoken package

Viewed 816

I am using the quasar cli to create a vue 3 application. I have installed jsonwebtoken via yarn. When I try to compile the application I get the errors listed below:

App •  ERROR  •  UI  in ./node_modules/jwa/index.js

Module not found: Can't resolve imported dependency "crypto"
Did you forget to install it? You can run: yarn add crypto

 App •  ERROR  •  UI  in ./node_modules/jwa/index.js

Module not found: Can't resolve imported dependency "util"
Did you forget to install it? You can run: yarn add util

 App •  ERROR  •  UI  in ./node_modules/jws/lib/data-stream.js

Module not found: Can't resolve imported dependency "stream"
Did you forget to install it? You can run: yarn add stream

 App •  ERROR  •  UI  in ./node_modules/jws/lib/data-stream.js

Module not found: Can't resolve imported dependency "util"
Did you forget to install it? You can run: yarn add util

I can run "yarn add util" and "yarn add stream" and those errors go away but I do not know if that is the correct solution to the problem. Regardless, I can't just run "yarn add crypto" to resolve that error. When you do you get the following warning...

warning crypto@1.0.1: This package is no longer supported. It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in.

But I'm not sure what needs to be done here to "switch to the one that's built-in" and am very curious if everyone runs into this when using jsonwebtoken?

1 Answers

I was never able to figure out how to resolve the issues I was having trying to use jsonwebtoken. I also tried several other JWT packages with no success as well. Finally I ran across jwt-decode and since the only thing i needed to do on the client was decode the token I tried it and it worked great and was VERY easy to use:

https://www.npmjs.com/package/jwt-decode

Related