workos / workos-node

Official Node SDK for interacting with the WorkOS API
https://workos.com/docs/sdk/node
MIT License
115 stars 28 forks source link

TypeError: Illegal invocation #1070

Closed atmcalbt closed 1 month ago

atmcalbt commented 2 months ago

Overview

I've set up a basic API using Cloudflare Workers + Hono. When integrating the WorkOS Node.js library I'm seeing Unexpected error: TypeError: Illegal invocation when calling asynchronous WorkOS functions (such as userManagement.authenticateWithCode).

Example

type Bindings = {
  WORKOS_CLIENT_ID: string
  WORKOS_API_KEY: string
}

const app = new Hono<{ Bindings: Bindings }>()

app.get(
  '/callback',
  async (ctx) => {
    const workos = new WorkOS(ctx.env.WORKOS_API_KEY);

    const { accessToken, refreshToken } =
      await workos.userManagement.authenticateWithCode({
        code: ctx.var.code,
        clientId: ctx.env.WORKOS_CLIENT_ID
      })

    return ctx.body(null, 204)
  }
)

Error

Error: Unexpected error: TypeError: Illegal invocation
    at WorkOSWorker.handleHttpError (file:///Users/[...]/api/.wrangler/tmp/dev-8ZYyNY/index.js:4189:17)
    at WorkOSWorker.<anonymous> (file:///Users/[...]/api/.wrangler/tmp/dev-8ZYyNY/index.js:4130:18)
    at Generator.throw (<anonymous>)
    at rejected (file:///Users/[...]/api/.wrangler/tmp/dev-8ZYyNY/index.js:4038:36) {
  stack: Error: Unexpected error: TypeError: Illegal invoca…ps/api/.wrangler/tmp/dev-8ZYyNY/index.js:4038:36),
  message: Unexpected error: TypeError: Illegal invocation

Extra

I'm using the latest version of the library (^7.11.3). I've tried to downgrade the version (down to 7.0.0) and I'm still seeing this. I'm also seeing this locally, not just remotely. Worth mentioning that code and clientId are strings.

My best guess is that this is related to Hono? I'm unsure how to fix it, so any guidance is much appreciated.

atmcalbt commented 2 months ago

Quick update: downgrading the library to 6.8.0 did the trick. Note that the issue still persists on newer versions.

chantastic commented 1 month ago

Hi @atmcalbt! I do developer education at WorkOS. And I ran into the same issue with v7 on Cloudflare Workers.

We don't have an immediate path forward on this but we're looking into what's causing the issue and hope to have a better solution (than downgrading) soon.

danjenkins commented 1 month ago

@chantastic any progress on this? I've just hit this issue too.

PaulAsjes commented 1 month ago

This is fixed in v7.19.0! Closing this for now, feel free to re-open if you're still running into issues.