-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can't import jsonwebtoken in modern typescript esm app #785
Comments
This works for me in typescript... and the types all come through fine |
@jd-0001 that is not related to this issue |
@diroussel Sorry, I thought this was related to this. May I know what's causing this so I can open new issue here. Thanks. |
I would suggest setting a debugger breakpoint and following what is really going on. If you are able to get a working code sample maybe post it on stackoverflow. But github issues are to report bugs or request features, not to ask for debugging help. |
Hi! |
Unfortunately We now use import jsonwebtoken from 'jsonwebtoken';
const { sign, decode, verify } = jsonwebtoken; This works fine for SvelteKit + Vite. But nevertheless it would be great if this package can get native ESM support. |
Hi @vekunz, I found your comment and have the exact same code for SvelteKit + Vite. The web app is deployed to Vercel and I notice I'm now getting the following error at runtime:
This is with Node.js 16 configured on Vercel. If you host on Vercel, do you use Node.js 16? If not on Vercel, do you mind sharing where your app is hosted? Thanks |
Hello @mikenikles, we use SvelteKit with adapter-node and run it in a Docker container with Node 16. |
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. |
I ended up doing the same. Locally it works fine while developing but I realized this is broken when I built on Stormkit. Tried building locally, it gives me the same error:
It works fine with https://github.com/panva/jose though, took a couple of minutes to rewrite as mentioned! Thanks 🙏 |
@jd-solanki Did you find any solution for this error? |
No 😞 |
I was able to properly load jsonwebtoken with |
Almost all "import" methods only support older versions of Node.js. Just use "fastify/jwt" or "jwt-decode" pacakge |
This worked for me! |
@RaghavRagh you are trying to access the jwtwebtoken on client side which is not allowed, by implementing it on server side you will not be facing this issue |
we can't properly import this library in a modern typescript project. here's the problem:
import * as jwt from "jsonwebtoken"
default
contains what i need, sign, verify, etc@types/jsonwebtoken
as you can see there's an incompatibility between what can actually be imported at runtime, versus what the
@types
typings allow us to import. on one hand, this could be seen as a deficiency in the community@types
typingson the other hand, a fundamental fix for this problem would be:
related issue #655
in the meantime, here's the hack i used to circumvent this problem
create a shim module
badmodules/jsonwebtoken.ts
import the shim module instead
The text was updated successfully, but these errors were encountered: