Repository: next.js
Issue: MDX components.wrapper cant be a client component with output: export
Labels: bug,Markdown (MDX)

### Link to the code that reproduces this issue

https://github.com/h3rmanj/nextjs-mdx-client-wrapper-repro

### To Reproduce

1. Setup Next.js with MDX
2. Add a `page.mdx`
3. Add a client component as a wrapper to `mdx-components.tsx`
4. Set `output` mode to `export`
5. `npm run build`

### Current vs. Expected behavior

Currently the build fails with the following output:

<details>
<summary>build output</summary>

```
> nextjs-mdx-client-wrapper-repro@0.1.0 build
> next build

⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
Attention: Next.js now collects completely anonymous telemetry regarding usage.
This information is used to shape Next.js' roadmap and prioritize features.
You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
https://nextjs.org/telemetry

   ▲ Next.js 14.0.4-canary.5

   Creating an optimized production build ...
 ✓ Compiled successfully
   Linting and checking validity of types ...
   Collecting page data ...
   Generating static pages (0/5) ...

   Generating static pages (1/5) 
Error: r]: Page with `dynamic = "error"` couldn't be rendered statically because it used `searchParams.toJSON`.
    at i (/home/runner/work/nextjs-mdx-client-wrapper-repro/nextjs-mdx-client-wrapper-repro/.next/server/chunks/449.js:1:81115)
    at Object.get (/home/runner/work/nextjs-mdx-client-wrapper-repro/nextjs-mdx-client-wrapper-repro/.next/server/chunks/449.js:1:80259)
    at stringify (<anonymous>)
    at eE (/home/runner/work/nextjs-mdx-client-wrapper-repro/nextjs-mdx-client-wrapper-repro/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:131997)
    at eR (/home/runner/work/nextjs-mdx-client-wrapper-repro/nextjs-mdx-client-wrapper-repro/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:132440)
    at Timeout._onTimeout (/home/runner/work/nextjs-mdx-client-wrapper-repro/nextjs-mdx-client-wrapper-repro/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:129220)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7) {
  code: 'NEXT_STATIC_GEN_BAILOUT'
}
Error: r]: Page with `dynamic = "error"` couldn't be rendered statically because it used `searchParams.toJSON`.
    at i (/home/runner/work/nextjs-mdx-client-wrapper-repro/nextjs-mdx-client-wrapper-repro/.next/server/chunks/449.js:1:81115)
    at Object.get (/home/runner/work/nextjs-mdx-client-wrapper-repro/nextjs-mdx-client-wrapper-repro/.next/server/chunks/449.js:1:80259)
    at stringify (<anonymous>)
    at eE (/home/runner/work/nextjs-mdx-client-wrapper-repro/nextjs-mdx-client-wrapper-repro/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:131997)
    at eR (/home/runner/work/nextjs-mdx-client-wrapper-repro/nextjs-mdx-client-wrapper-repro/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:132440)
    at Timeout._onTimeout (/home/runner/work/nextjs-mdx-client-wrapper-repro/nextjs-mdx-client-wrapper-repro/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:129220)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7) {
  code: 'NEXT_STATIC_GEN_BAILOUT'
}

Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Page with `dynamic = "error"` couldn't be rendered statically because it used `searchParams.toJSON`.
    at i (/home/runner/work/nextjs-mdx-client-wrapper-repro/nextjs-mdx-client-wrapper-repro/.next/server/chunks/449.js:1:81115)
    at Object.get (/home/runner/work/nextjs-mdx-client-wrapper-repro/nextjs-mdx-client-wrapper-repro/.next/server/chunks/449.js:1:80259)
    at stringify (<anonymous>)
    at eE (/home/runner/work/nextjs-mdx-client-wrapper-repro/nextjs-mdx-client-wrapper-repro/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:131997)
    at eR (/home/runner/work/nextjs-mdx-client-wrapper-repro/nextjs-mdx-client-wrapper-repro/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:132440)
    at Timeout._onTimeout (/home/runner/work/nextjs-mdx-client-wrapper-repro/nextjs-mdx-client-wrapper-repro/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:129220)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7)

   Generating static pages (2/5) 

   Generating static pages (3/5) 

 ✓ Generating static pages (5/5) 

> Export encountered errors on following paths:
	/page: /
Error: Process completed with exit code 1.
```

</details>

I expected this to work as I haven't done anything special regarding dynamic routes.

### Verify canary release

- [X] I verified that the issue exists in the latest Next.js canary release

### Provide environment information

```
Operating System:
  Platform: linux
  Arch: x64
  Version: #15~22.04.1-Ubuntu SMP Fri Oct  6 13:20:44 UTC 2023
Binaries:
  Node: 20.9.0
  npm: 10.1.0
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 14.0.4-canary.5
  eslint-config-next: 14.0.1
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: export
```


### Which area(s) are affected? (Select all that apply)

App Router, MDX (@next/mdx)

### Additional context

If the wrapper component is not a client component, it works.  
If output is not set to `export`, it works.

Seems like a combination of the two.