-
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
import jsonwebtoken
throws error
#963
Comments
Facing same issue! what happened? For me, not working with even 9.0.0. I can access other functions such as |
I started experiencing this problem after I switched to using ESM modules on my code. The solution, as the error message suggests, was to stop using named exports and rely on the default import syntax. |
It can be written like this
|
I just commented |
Same problem when importing the error classes on v.9.0.2, and TypeScript doesn't throw any error in editor, but Nitro (Nuxt v3.13.0) does. So far, I only find a solution by not destructuring the module and importing everything. import { JsonWebTokenError, TokenExpiredError } from 'jsonwebtoken' // ❌
import jwt from 'jsonwebtoken' // 👍
jwt.JsonWebTokenError // 👍 Idk if it's a jsonwebtoken or nitro/nuxt related bug... |
Just ran into this issue as well using Typescript. I want to deploy some ESM code that is using the sign function like this: I guess the issue is that this package is CommonJS only, so when importing this into ESM, named exports are not working and you have to fall back on using default import. Still not sure why Typescript thinks it should work though. |
ChatGPT told me this too after even your solution wouldn't work. It suggested using |
Description
import
jsonwebtoken
throws errorReproduction
The code:
The error message:
It works on v9.0.0 but fails on 9.0.2.
Environment
The text was updated successfully, but these errors were encountered: