Skip to content

[BUG] Next.js16 - Clerk @clerk/nextjs/server import crashes with cacheComponents: true in preview mode #1062

@darknblack

Description

@darknblack

Describe the bug

When importing { auth } from '@clerk/nextjs/server' in a Next.js layout component, the application crashes during preview mode (pnpm preview) but works correctly during development mode (pnpm dev).

Code Example

// app/(admin)/layout.tsx
import { auth } from '@clerk/nextjs/server';

export default async function AdminLayout({ children }: { children: React.ReactNode }) {
  const { userId } = await auth();
  // ... rest of component
}

Screenshot

Image

Steps to reproduce

  1. Import { auth } from '@clerk/nextjs/server' in a layout file (e.g., app/(admin)/layout.tsx)
  2. Run pnpm dev - application works correctly
  3. Run pnpm preview - application crashes

Expected behavior

The application should work correctly in both development and preview modes when importing from @clerk/nextjs/server.

@opennextjs/cloudflare version

1.14.7

Wrangler version

4.54.0

next info output

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 31895
  Available CPU cores: 16
Binaries:
  Node: 20.19.0
  npm: 10.8.2
  Yarn: 4.4.0
  pnpm: 10.20.0
Relevant Packages:
  next: 16.0.7 // There is a newer version (16.1.1) available, upgrade recommended!      
  eslint-config-next: N/A
  react: 19.2.1
  react-dom: 19.2.1
  typescript: 5.9.3
Next.js Config:
  output: N/A
 ⚠ There is a newer version (16.1.1) available, upgrade recommended! 
   Please try the latest canary version (`npm install next@canary`) to confirm the issue still exists before creating a new issue.
   Read more - https://nextjs.org/docs/messages/opening-an-issue

Additional context

This appears to be a compatibility issue between @clerk/nextjs/server and the OpenNext Cloudflare adapter. The import works in standard Next.js development mode but fails when using the OpenNext Cloudflare build/preview pipeline.

Note: I am using the cache component feature (cacheComponents: true in next.config.mjs). This may be related to the issue.

// next.config.mjs
const nextConfig = {
  cacheComponents: true,
  cacheLife: {
    default: {
      stale: 60 * 60 * 24 * 1, // 1 day
      revalidate: 60 * 60 * 24 * 2, // 2 days
      expire: 60 * 60 * 24 * 7, // 1 week
    },
  },
};

Environment

  • Package: @opennextjs/cloudflare@1.14.7
  • Next.js: 16.0.7
  • Clerk: @clerk/nextjs@6.36.5

Build/Preview Scripts

{
  "preview": "opennextjs-cloudflare build && opennextjs-cloudflare preview",
  "dev": "next dev --turbopack -H 0.0.0.0"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions