Closed arvinxx closed 3 months ago
Hi @arvinxx, thanks for raising the issue! We're working on a fix for it and it should be released soon.
@arvinxx The fix has been merged and will soon release a patch for @clerk/nextjs
! 🫡
Hi @LauraBeatris I'm still facing what seems to be the same issue in my project
"@clerk/nextjs": "^5.2.3",
"next": "14.1.3",
middleware.ts
import { clerkMiddleware } from "@clerk/nextjs/server";
export default clerkMiddleware();
console.log("middleware called");
export const config = {
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
};
Error
⨯ node:async_hooks
Module build failed: UnhandledSchemeError: Reading from "node:async_hooks" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
Import trace for requested module:
node:async_hooks
./node_modules/@clerk/nextjs/dist/esm/server/clerkMiddleware.js
./node_modules/@clerk/nextjs/dist/esm/server/index.js
./src/app/profile/[[...profile]]/page.jsx
Hi @LauraBeatris I'm still facing what seems to be the same issue in my project
"@clerk/nextjs": "^5.2.3", "next": "14.1.3",
middleware.ts
import { clerkMiddleware } from "@clerk/nextjs/server"; export default clerkMiddleware(); console.log("middleware called"); export const config = { matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"], };
Error
⨯ node:async_hooks Module build failed: UnhandledSchemeError: Reading from "node:async_hooks" is not handled by plugins (Unhandled scheme). Webpack supports "data:" and "file:" URIs by default. You may need an additional plugin to handle "node:" URIs. Import trace for requested module: node:async_hooks ./node_modules/@clerk/nextjs/dist/esm/server/clerkMiddleware.js ./node_modules/@clerk/nextjs/dist/esm/server/index.js ./src/app/profile/[[...profile]]/page.jsx
Hey @shawnesquivel! Thanks for reporting, I'm looking into this now and will keep you updated.
Thanks @LauraBeatris . I tried making a minimal repro with no luck – it seems to work on a fresh repo when using the quickstart instructions.
As an interim, here's what I've tried on my own project:
.next
directory, node_modules
foldersimport { SignedOut, SignedIn, SignInButton } from "@clerk/nextjs";
import { auth, currentUser } from "@clerk/nextjs/server";
Let me know if there are specific actions I can take to help diagnose the issue better.
@LauraBeatris I can confirm that this issue has presently went away when I stopped using it in a client component, denoted by the "use client" directive.
The docs do say it should be able to be used in client components though, so I think it's still a bug worth noting.
@LauraBeatris I can confirm that this issue has presently went away when I stopped using it in a client component, denoted by the "use client" directive.
The docs do say it should be able to be used in client components though, so I think it's still a bug worth noting.
Hi @shawnesquivel! auth()
and currentUser()
are server-side APIs only to be used from Next.js app router.
On client components, useAuth
should be used instead: https://clerk.com/docs/references/nextjs/read-session-data#client-side.
I agree that the error shown is confusing when using a server-side helper on a client-side component. On 5.1.0, the following was shown instead:
Error: Clerk: auth() was called but Clerk can't detect usage of clerkMiddleware() (or the deprecated authMiddleware()). Please ensure the following:
- clerkMiddleware() (or the deprecated authMiddleware()) is used in your Next.js Middleware.
- Your Middleware matcher is configured to match this route or page.
- If you are using the src directory, make sure the Middleware file is inside of it.
We should either continue displaying it or work on a better error message.
I just encountered this issue.
It seems that import { auth } from "@clerk/nextjs/server";
must be used in an async page.
It connection with the Import { auth }, the documentation displays const { userId } = auth();
and we just copy paste that into our code.
https://clerk.com/docs/references/nextjs/read-session-data
Kindly inform the team responsible for the documentatio to add await, thus const { userId } = await auth();
or explicitly say that's for server side.
Well, the Clerk team must improve the documentation so that we won't get this kind of simple issues and waste both your time and ours.
Thanks for your help. Great product!
@LauraBeatris I can confirm that this issue has presently went away when I stopped using it in a client component, denoted by the "use client" directive. The docs do say it should be able to be used in client components though, so I think it's still a bug worth noting. https://clerk.com/docs/references/nextjs/read-session-data
Hi @shawnesquivel!
auth()
andcurrentUser()
are server-side APIs only to be used from Next.js app router.On client components,
useAuth
should be used instead: https://clerk.com/docs/references/nextjs/read-session-data#client-side.I agree that the error shown is confusing when using a server-side helper on a client-side component. On 5.1.0, the following was shown instead:
Error: Clerk: auth() was called but Clerk can't detect usage of clerkMiddleware() (or the deprecated authMiddleware()). Please ensure the following: - clerkMiddleware() (or the deprecated authMiddleware()) is used in your Next.js Middleware. - Your Middleware matcher is configured to match this route or page. - If you are using the src directory, make sure the Middleware file is inside of it.
We should either continue displaying it or work on a better error message.
Hey everyone! We're actively working to improve the error message when server-side helpers are used in a client-side context.
I'll re-open this issue again and related to a PR soon.
Hi @LauraBeatris @shawnesquivel , I'm facing the same issue. Is there a way to resolve this?
Preliminary Checks
Reproduction
https://github.com/lobehub/lobe-chat/tree/reproduction/clerk-nextjs-5.2.0
Publishable key
no need, it's a build time issue
Description
here is the build log:
you can see the error from
@clerk/nextjs
. please remove this usage:https://github.com/clerk/javascript/blob/1a704ed9de3ad222ff17d10cb383639b2fc038b9/packages/nextjs/src/server/clerkMiddleware.ts#L10
Environment