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: Illegal invocation #1070

Open
atmcalbt opened this issue Jun 24, 2024 · 1 comment
Open

TypeError: Illegal invocation #1070

atmcalbt opened this issue Jun 24, 2024 · 1 comment

Comments

@atmcalbt
Copy link

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
Copy link
Author

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

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

1 participant