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

TypeError: Right hand side of instanceof is not an object #939

Open
176noud opened this issue Sep 10, 2023 · 13 comments
Open

TypeError: Right hand side of instanceof is not an object #939

176noud opened this issue Sep 10, 2023 · 13 comments

Comments

@176noud
Copy link

176noud commented Sep 10, 2023

[email protected] => [email protected]
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.

@shakhzodkudratov
Copy link

facing exactly the same issue

@AlexRoosWork
Copy link

AlexRoosWork commented Sep 12, 2023

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.

@ehuff700
Copy link

ehuff700 commented Sep 13, 2023

Also using Bun and this issue is happening for me as well.

EDIT: Coming back to this to mention that migrating to https://github.com/panva/jose fixed this issue for me.

EDIT 2: Found the issue, this will be broken for all bun users: https://bun.sh/docs/runtime/nodejs-apis#node-crypto. A CTRL+F shows that KeyObject, createSecretKey, and createPrivateKey are all missing... Those are requirements of sign.js

@im-not-developer
Copy link

be faced with the same problem.

@iraycd
Copy link

iraycd commented Oct 9, 2023

It's a issue with Bun:
oven-sh/bun#4983

I have updated to "FROM oven/bun:canary" on Dockerfile.
This resolved the issue.

@Gnex77
Copy link

Gnex77 commented Oct 20, 2023

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.

@mrksph
Copy link

mrksph commented Nov 5, 2023

Same here, deleted node_modules, reinstalled all dependencies and still got the same error. Will be trying to downgrade

I use NVM but I only have two node versions installed

PS D:\workspace\> nvm ls

    18.12.1
  * 16.20.0 (Currently using 64-bit executable)
next.js 13.5.6
npm 8.19.4
node v16.20.0
jsonwebtoken 9.0.2

const decoded = jwt.verify(token, '{{SECRET}}');

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

Edit: After downgrading jsonwebtoken to 8.5.1 it works but I don't expect having to downgrade

@wissenstein
Copy link

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?

@eric-sison
Copy link

Facing the same issue.

next: 14.1.0
node: 20.9.0
npm: 10.1.0
jsonwebtoken: ^9.0.2
@types/jsonwebtoken: ^9.0.5

@alexkirillovtech
Copy link

alexkirillovtech commented Feb 26, 2024

Facing same issue

    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-i18next": "^11.18.5",
    "react-router-dom": "^6.2.1",
    "ua-parser-js": "^1.0.32",
    "webpack-dev-middleware": "^4.3.0",
    "jsonwebtoken": "^9.0.2"

@johannchopin-buyco
Copy link

Hey @jakelacey2012 👋 Could you please tell us what's the status on this one as v9 is definitely broken? Thanks for the work put on this package by the way.

lencioni added a commit to happo/happo.io that referenced this issue Jun 18, 2024
We received a report of this package failing with the following error:

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

The stack trace pointed at the jsonwebtoken package as the source.

At first it looked like this may be a problem on older versions of Node,
but it turned out that they were using a relatively recent version
(v18.17.1).

It appears that a lot of other people may be running into a similar
issue:

- auth0/node-jsonwebtoken#939
- auth0/node-jsonwebtoken#892

People have reported success by either downgrading jsonwebtoken to v8 or
replacing it with jose. Since we updated to jsonwebtoken v9 to fix a
security vulnerability, I don't think it is a great idea to go back to
v8.

jose seems to be well-supported, healthy, and active:

https://snyk.io/advisor/npm-package/jose

Let's give this a shot!

The API is a little bit different than jsonwebtoken, but for the most
part I think the new version is simple enough to transition to. I set
the alg properity to HS256, since it is required to specify the alg and
that is what jsonwebtoken uses as the default.
lencioni added a commit to happo/happo.io that referenced this issue Jun 18, 2024
We received a report of this package failing with the following error:

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

The stack trace pointed at the jsonwebtoken package as the source.

At first it looked like this may be a problem on older versions of Node,
but it turned out that they were using a relatively recent version
(v18.17.1).

It appears that a lot of other people may be running into a similar
issue:

- auth0/node-jsonwebtoken#939
- auth0/node-jsonwebtoken#892

People have reported success by either downgrading jsonwebtoken to v8 or
replacing it with jose. Since we updated to jsonwebtoken v9 to fix a
security vulnerability, I don't think it is a great idea to go back to
v8.

jose seems to be well-supported, healthy, and active:

https://snyk.io/advisor/npm-package/jose

Let's give this a shot!

The API is a little bit different than jsonwebtoken, but for the most
part I think the new version is simple enough to transition to. I set
the alg properity to HS256, since it is required to specify the alg and
that is what jsonwebtoken uses as the default.

It seems that jose uses `||=` syntax which is not supported on node 14,
so I am also removing the node 14 tests as part of this commit. While I
was in there I figured I might as well get the tests running on node 20
and node 22.
lencioni added a commit to happo/happo.io that referenced this issue Jun 18, 2024
We received a report of this package failing with the following error:

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

The stack trace pointed at the jsonwebtoken package as the source.

At first it looked like this may be a problem on older versions of Node,
but it turned out that they were using a relatively recent version
(v18.17.1).

It appears that a lot of other people may be running into a similar
issue:

- auth0/node-jsonwebtoken#939
- auth0/node-jsonwebtoken#892

People have reported success by either downgrading jsonwebtoken to v8 or
replacing it with jose. Since we updated to jsonwebtoken v9 to fix a
security vulnerability, I don't think it is a great idea to go back to
v8.

jose seems to be well-supported, healthy, and active:

https://snyk.io/advisor/npm-package/jose

Let's give this a shot!

The API is a little bit different than jsonwebtoken, but for the most
part I think the new version is simple enough to transition to. I set
the alg properity to HS256, since it is required to specify the alg and
that is what jsonwebtoken uses as the default.

It seems that jose uses `||=` syntax which is not supported on node 14,
so I am also removing the node 14 tests as part of this commit. While I
was in there I figured I might as well get the tests running on node 20
and node 22.
lencioni added a commit to happo/happo.io that referenced this issue Jun 18, 2024
We received a report of this package failing with the following error:

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

The stack trace pointed at the jsonwebtoken package as the source.

At first it looked like this may be a problem on older versions of Node,
but it turned out that they were using a relatively recent version
(v18.17.1).

It appears that a lot of other people may be running into a similar
issue:

- auth0/node-jsonwebtoken#939
- auth0/node-jsonwebtoken#892

People have reported success by either downgrading jsonwebtoken to v8 or
replacing it with jose. Since we updated to jsonwebtoken v9 to fix a
security vulnerability, I don't think it is a great idea to go back to
v8.

jose seems to be well-supported, healthy, and active:

https://snyk.io/advisor/npm-package/jose

Let's give this a shot!

The API is a little bit different than jsonwebtoken, but for the most
part I think the new version is simple enough to transition to. I set
the alg properity to HS256, since it is required to specify the alg and
that is what jsonwebtoken uses as the default.

It seems that jose uses `||=` syntax which is not supported on node 14,
so I am also removing the node 14 tests as part of this commit.
lencioni added a commit to happo/happo.io that referenced this issue Jun 18, 2024
We received a report of this package failing with the following error:

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

The stack trace pointed at the jsonwebtoken package as the source.

At first it looked like this may be a problem on older versions of Node,
but it turned out that they were using a relatively recent version
(v18.17.1).

It appears that a lot of other people may be running into a similar
issue:

- auth0/node-jsonwebtoken#939
- auth0/node-jsonwebtoken#892

People have reported success by either downgrading jsonwebtoken to v8 or
replacing it with jose. Since we updated to jsonwebtoken v9 to fix a
security vulnerability, I don't think it is a great idea to go back to
v8.

jose seems to be well-supported, healthy, and active:

https://snyk.io/advisor/npm-package/jose

Let's give this a shot!

The API is a little bit different than jsonwebtoken, but for the most
part I think the new version is simple enough to transition to. I set
the alg properity to HS256, since it is required to specify the alg and
that is what jsonwebtoken uses as the default.

It seems that jose uses `||=` syntax which is not supported on node 14,
so I am also removing the node 14 tests as part of this commit.
lencioni added a commit to happo/happo.io that referenced this issue Jun 18, 2024
We received a report of this package failing with the following error:

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

The stack trace pointed at the jsonwebtoken package as the source.

At first it looked like this may be a problem on older versions of Node,
but it turned out that they were using a relatively recent version
(v18.17.1).

It appears that a lot of other people may be running into a similar
issue:

- auth0/node-jsonwebtoken#939
- auth0/node-jsonwebtoken#892

People have reported success by either downgrading jsonwebtoken to v8 or
replacing it with jose. Since we updated to jsonwebtoken v9 to fix a
security vulnerability, I don't think it is a great idea to go back to
v8.

jose seems to be well-supported, healthy, and active:

https://snyk.io/advisor/npm-package/jose

Let's give this a shot!

The API is a little bit different than jsonwebtoken, but for the most
part I think the new version is simple enough to transition to. I set
the alg properity to HS256, since it is required to specify the alg and
that is what jsonwebtoken uses as the default.

It seems that jose uses `||=` syntax which is not supported on node 14,
so I am also removing the node 14 tests as part of this commit.
@SashaJson
Copy link

Facing the same issue

"dependencies": { "bcrypt": "^5.1.1", "jsonwebtoken": "^9.0.2" }

node v18.6.0

@rubych-nz
Copy link

Facing the same issue
node v18.18.0
jsonwebtoken 9.0.2

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