Closed natnaelmb1 closed 2 years ago
I think I have found the problem. It's with my webpack version. The only reason I found out about it is because I created a new create-react-app
project and it failed. But it showed me a helpful message. I suggest Vite also showing those error messages would really be helpful.
What error message did webpack gave? And what was the core issue?
tl;dr: jsonwebtoken uses Node core modules. Use jwt-decode instead.
jsonwebtoken
uses Node core modules which won't work in the browser. I guess that @phatnael got a note from webpack (after upgrading to 5.x) that webpack < 5 used to include Node polyfills but not anymore.
This is not an issue with Vite.
Yeah. I figured out that the problem was not with vite. I am using jwt-decode. But, I still think that vite should show a helpful error instead of a blank page, just like create-react-app
does.
Describe the bug
Importing jsonwebtoken inside my project
Uncaught TypeError: Cannot read properties of undefined (reading 'from')
on Chrome andUncaught TypeError: Buffer2 is undefined
on Firefox. I am using vite(2.7.2) and jsonwebttoken(8.5.1). I tried both yarn and npm to install the package. Same result.Reproduction
https://stackblitz.com/edit/vitejs-vite-dqj9vs?file=main.js
System Info
Validations