next.js icon indicating copy to clipboard operation
next.js copied to clipboard

After upgrading to Next.js 16.0.1, the build fails during prerendering of the internal /_not-found route with the following error:

Open mayank1513 opened this issue 2 months ago • 5 comments

Link to the code that reproduces this issue

https://github.com/md2docx/mdast2docx/tree/a9078b882ec58f3cdafb68446c8d0c679a1907b8/examples/nextjs

To Reproduce

  1. clone repo and install dependencies
  2. run build command

Current vs. Expected behavior

Current:

Build fails with following error:

Error occurred prerendering page "/_not-found".
Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server". Or maybe you meant to call this function rather than return it.
  {linkComponent: function i}
                  ^^^^^^^^^^
Export encountered an error on /_not-found/page: /_not-found, exiting the build.

Expected: should build without errors as with next.js 15

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Home Single Language
  Available memory (MB): 16168
  Available CPU cores: 8
Binaries:
  Node: 22.19.0
  npm: 10.9.3
  Yarn: 1.22.19
  pnpm: 10.20.0
Relevant Packages:
  next: 16.0.1 // Latest available version is detected (16.0.1).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A
Done in 3.06s.

Which area(s) are affected? (Select all that apply)

Not sure

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

No response

mayank1513 avatar Oct 31 '25 07:10 mayank1513

I'm seeing the same error in https://github.com/ruffle-rs/ruffle-rs.github.io/pull/466, but in stringify, not {linkComponent: function i}:

Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server". Or maybe you meant to call this function rather than return it.
  {size: "lg", color: "gray", variant: ..., component: function i, href: ..., target: ..., title: ..., children: ...}
                                                       ^^^^^^^^^^
    at stringify (<anonymous>) {
  digest: '331849362'
}

danielhjacobs avatar Nov 03 '25 15:11 danielhjacobs

Problem not happening on 16.0.0.

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!

diaz-hfc avatar Nov 03 '25 21:11 diaz-hfc

https://react.dev/reference/rsc/use-client#serializable-types

Functions that are not exported from client-marked module

I could fix this issue by creating custom next/link component like below:

// ./CustomNextLink.tsx
'use client'

export { default as CustomLink } from 'next/link'
import { CustomLink } from './CustomNextLink';

<Header linkComponent={CustomLink} />

However, since next/link is already marked as 'use client', so I'm wondering why this workaround is necessary. 🤔

ktmouk avatar Nov 07 '25 05:11 ktmouk

Hi, I was able to reproduce the issue.

I observed that you can unblock with a "pass through re-export" file:

'use client'

import Link from 'next/link'

export { Link }

NOT saying you should do that - I've asked the team to look into this. Thanks for the report.

I think the issue was introduced when this module was included https://github.com/vercel/next.js/blob/ad93e452a458a27110e7cf5e8272e40d4741b756/packages/next/src/client/app-dir/link.react-server.tsx#L4 - hopefully we'll have time to loop back on this soon.

icyJoseph avatar Nov 10 '25 09:11 icyJoseph

This still blocks https://github.com/ruffle-rs/ruffle-rs.github.io/pull/481.

torokati44 avatar Dec 09 '25 13:12 torokati44