node-jsonwebtoken: TypeError: Right hand side of instanceof is not an object

jsonwebtoken@9.0.0 => jsonwebtoken@9.0.2 bunjs typescript

When generating a token using the jsonwebtoken library instead of returning a valid token it returns an error: 103 | 104 | if (!secretOrPrivateKey && options.algorithm !== 'none') { 105 | return failure(new Error('secretOrPrivateKey must have a value')); 106 | } 107 | 108 | if (secretOrPrivateKey != null && !(secretOrPrivateKey instanceof KeyObject)) { ^ TypeError: Right hand side of instanceof is not an object at /home/d/Desktop/smth/v5/node_modules/jsonwebtoken/sign.js:108:38 at /home/d/Desktop/smth/v5/index.ts:48:32 at processTicksAndRejections (:1:2602) POST - http://localhost:8080/api/auth/register failed

Using valid code: const token = await jwt.sign({ username: username }, jwtSecret);

Returns a jwt token on versions prior to 9.0.0, preferably 8.5.1 works without issues.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 11
  • Comments: 15

Commits related to this issue

Most upvoted comments

me three, not using bun btw (also using v9.0.2)

and yes, I can confirm that downgrading to 8.5.1 fixes this issue.

I am also seeing this error in the version 9.0.2. Not using bun. Using node v18.18.2. When I set the version to 8.5.1 error goes away. Please look into this issue, I would like to use the latest version of the library.

Having the same issue node v22.12.0 jsonwebtoken 9.0.2

Hi! I am using the following environment:

yarn 1.22.19
npm 10.1.0
node 20.8.0
jsonwebtoken 9.0.2

When I try to execute the following line:

const token = jwt.verify(accessToken, 'secret');

I get the following error:

TypeError: Right-hand side of 'instanceof' is not an object

Can you check please?