clerk / javascript

Official Javascript repository for Clerk authentication
https://clerk.com
MIT License
1.02k stars 231 forks source link

TypeError: Cannot read properties of undefined (reading 'timeoutType') #1080

Closed magnusrodseth closed 1 year ago

magnusrodseth commented 1 year ago

To set the stage, I am using a Turborepo with Next.js, tRPC and Clerk for authentication and user management.

As a preface: I started by asking in the Discussion in the tRPC repository, and the answer I got there was the following:

It's Node.js, and to be more specific, it's Unidici, their HTTP client. There are only 2 places where it can break there - nodejs/undici@dc8d111/lib/client.js#L1207-L1220

I have now setup 2 Next.js repositories which both have only Clerk in common, and the error still occurs. Hence, this leads me to believe the error I get stems from Clerk.

Ever since the start of my project, I sometimes get this error message:

@acme/web:dev: error - unhandledRejection: TypeError: Cannot read properties of undefined (reading 'timeoutType')
@acme/web:dev:     at _resume (evalmachine.<anonymous>:11000:33)
@acme/web:dev:     at resume (evalmachine.<anonymous>:10969:7)
@acme/web:dev:     at connect (evalmachine.<anonymous>:10956:7)
@acme/web:dev: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
@acme/web:dev: TypeError: Cannot read properties of undefined (reading 'timeoutType')
@acme/web:dev:     at _resume (evalmachine.<anonymous>:11000:33)
@acme/web:dev:     at resume (evalmachine.<anonymous>:10969:7)
@acme/web:dev:     at connect (evalmachine.<anonymous>:10956:7)

The error happens sporadically, and I have not been able to pinpoint any pattern of it occurring. The thing that baffles me is that when I Google this error, no other discussions around it exist.

It may happen when fetching data asynchronously between the tRPC client and server, with the Clerk context in between.

The stack trace is also very challenging to navigate, and does not offer much help. I have now concluded that timeoutType is something related to undici.

Do you have any general recommendations on how to debug and fix this issue? Do you have an idea under what circumstances this can be triggered?

dimkl commented 1 year ago

hello @magnusrodseth Could you provide a repository to try and reproduce this case? The undici is not a first level dependency of the @clerk/nextjs but it's a dependency of the miniflare devDependency of @clerk/backend which is being used by @clerk/nextjs. Have you tried checking the stack trace of :

process.on('unhandledRejection', error => {
    console.error(error);
});

I believe that using a production build would not raise this error since that dependency is not being used. But you won't be able to use the development goodies that NexJS provides (HMR, ...).

magnusrodseth commented 1 year ago

This makes a lot of sense, as I have not been able to reproduce the error in production. I'll see if I can get a reproducible repository up and running.

mrtns commented 1 year ago

I'm encountering this issue in my next+trpc+clerk app as well. Happens in dev but not in production.

magnusrodseth commented 1 year ago

@mrtns Good to know that it's not just me. Would you be able to add a reproducible repository?

mrtns commented 1 year ago

It might be hard to systematically repro given that it's so intermittent for me. One thing I did change this morning though was upgrading from node 16 (v16.20.0) to 18 (v18.16.0). It might be too early to call, but so far I haven't seen the error since.

AlonMiz commented 1 year ago

having the same issue

error - unhandledRejection: TypeError: Cannot read properties of undefined (reading 'timeoutType')
    at _resume (evalmachine.<anonymous>:11000:33)
    at resume (evalmachine.<anonymous>:10969:7)
    at connect (evalmachine.<anonymous>:10956:7)
clerk-cookie commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

clerk-cookie commented 1 year ago

This issue was closed because it has been stalled for 10 days with no activity.

clerk-cookie commented 2 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.