Skip to content
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

Open
jim-king-2000 opened this issue Mar 15, 2024 · 4 comments
Open

import jsonwebtoken throws error #963

jim-king-2000 opened this issue Mar 15, 2024 · 4 comments

Comments

@jim-king-2000
Copy link

jim-king-2000 commented Mar 15, 2024

Description

import jsonwebtoken throws error

Reproduction

The code:

import { verify } from "jsonwebtoken";

The error message:

import { verify } from "jsonwebtoken";
         ^^^^^^
SyntaxError: Named export 'verify' not found. The requested module 'jsonwebtoken' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'jsonwebtoken';
const { verify } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:134:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:217:5)
    at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
    at async loadESM (node:internal/process/esm_loader:28:7)
    at async handleMainPromise (node:internal/modules/run_main:120:12)

Node.js v21.7.0

It works on v9.0.0 but fails on 9.0.2.

Environment

Please provide the following:

  • Version of this library used: 9.0.2
  • Version of the platform or framework used, if applicable:
  • Other relevant versions (language, server software, OS, browser):
  • Other modules/plugins/libraries that might be involved:
@amandesai01
Copy link

amandesai01 commented Apr 24, 2024

Facing same issue! what happened?

For me, not working with even 9.0.0. I can access other functions such as decode

@fuadsaud
Copy link

fuadsaud commented May 2, 2024

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.

@IYATT-yx
Copy link

IYATT-yx commented May 3, 2024

It can be written like this

import jwt from 'jsonwebtoken'; const { sign, verify } = jwt;

@amandesai01
Copy link

I just commented @ts-ignore before calling verify method and it all started working. Weird. Can anyone tell me what might be the issue? Using Nitro server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants