Open michaelmendoza opened 10 months ago
Hi @michaelmendoza , Any solution?
@Qolzam I just used a different library: jwt-decode. Ideally, they would just fix the issue in node-jsonwebtoken. But both libraries are by the same organization.
Also having the same issue on version 9.0.2
Yeah I had this, in my case it's caused by me trying to run it in the browser. See this
Maybe:
same problem. Have you solved it yet?
Description
Importing
decode
function from jsonwebtoken causes error. I am unable to import the 'decode' function as normal.I suspect that this is an issue with vite and svelte. Seems the package safe-buffer, that jsonwebtoken is dependant on, is doing something vite doesn't like saying
Module externalized for browser compatibility
meaning it is likely using a Node.js module that is not polyfilled in and the vite doesn't accept. That is just my guess. (See vite info on issue here. )If you make node-jsonwebtoken work with strict mode with all it's dependencies, this may fix this probelm.
Reproduction
In my code I used the following:
import { decode, sign } from 'jsonwebtoken';
I get the following errors:
Looking into the chrome debugger and stopping the code before the error it seems that it has to do with the package safe-buffer that jsonwebtoken is dependant on.
Environment
Using svelte (v4.0.5) with vite (v4.4.2) on macOS and test with Chrome browser (v120).