From e4713a8cdce2ba4828da93fe78a72c3dd138a26e Mon Sep 17 00:00:00 2001 From: Jacek Date: Sun, 19 Apr 2026 20:47:06 -0500 Subject: [PATCH 1/2] feat(nextjs): add helpful error for incorrect auth import - Add TypeScript-only error when importing auth from wrong path - Shows clear diff format for fixing the import - Explains auth is only available in server contexts --- .changeset/auth-import-error.md | 7 +++++++ packages/nextjs/src/index.ts | 14 ++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 .changeset/auth-import-error.md diff --git a/.changeset/auth-import-error.md b/.changeset/auth-import-error.md new file mode 100644 index 00000000000..a8949e8b0a5 --- /dev/null +++ b/.changeset/auth-import-error.md @@ -0,0 +1,7 @@ +--- +"@clerk/nextjs": patch +--- + +Improve developer experience for incorrect auth import + +Add helpful TypeScript error when importing `auth` from `@clerk/nextjs` instead of `@clerk/nextjs/server`. The error message shows exactly how to fix the import with a clear diff format and explains that `auth` is only available in server contexts. \ No newline at end of file diff --git a/packages/nextjs/src/index.ts b/packages/nextjs/src/index.ts index 65e061353bf..b3aa06b83f1 100644 --- a/packages/nextjs/src/index.ts +++ b/packages/nextjs/src/index.ts @@ -81,3 +81,17 @@ import type { ServerComponentsServerModuleTypes } from './components.server'; export const ClerkProvider = ComponentsModule.ClerkProvider as ServerComponentsServerModuleTypes['ClerkProvider']; export const Show = ComponentsModule.Show as ServerComponentsServerModuleTypes['Show']; + +/** + * `auth` is not available from this import path. + * + * **To fix this error:** + * ```diff + * - import { auth } from '@clerk/nextjs' + * + import { auth } from '@clerk/nextjs/server' + * ``` + * + * The `auth` function is only available in server-side contexts: + * API Routes, Server Components, Server Actions, and Middleware. + */ +export declare const auth: never; From b2e43705ae58f40e999ae4eac6180375f5d02e18 Mon Sep 17 00:00:00 2001 From: Jacek Date: Sun, 19 Apr 2026 21:28:02 -0500 Subject: [PATCH 2/2] fix: format code with prettier --- .changeset/auth-import-error.md | 4 +--- packages/nextjs/src/index.ts | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.changeset/auth-import-error.md b/.changeset/auth-import-error.md index a8949e8b0a5..6ac19aef736 100644 --- a/.changeset/auth-import-error.md +++ b/.changeset/auth-import-error.md @@ -2,6 +2,4 @@ "@clerk/nextjs": patch --- -Improve developer experience for incorrect auth import - -Add helpful TypeScript error when importing `auth` from `@clerk/nextjs` instead of `@clerk/nextjs/server`. The error message shows exactly how to fix the import with a clear diff format and explains that `auth` is only available in server contexts. \ No newline at end of file +Add helpful TypeScript error for incorrect `auth` import path \ No newline at end of file diff --git a/packages/nextjs/src/index.ts b/packages/nextjs/src/index.ts index b3aa06b83f1..25cea1d9d19 100644 --- a/packages/nextjs/src/index.ts +++ b/packages/nextjs/src/index.ts @@ -84,13 +84,13 @@ export const Show = ComponentsModule.Show as ServerComponentsServerModuleTypes[' /** * `auth` is not available from this import path. - * + * * **To fix this error:** * ```diff * - import { auth } from '@clerk/nextjs' * + import { auth } from '@clerk/nextjs/server' * ``` - * + * * The `auth` function is only available in server-side contexts: * API Routes, Server Components, Server Actions, and Middleware. */