Server code leaks to browser due to re-exporting pages.
The issue involves server code leaking to the browser when re-exporting pages in the Pages Router, specifically causing module resolution errors. The problem appears to be related to tree-shaking limitations in Next.js. The issue is somewhat clear but requires understanding of Next.js bundling behavior.
https://github.com/timheerwagen/re-export-page-server-code-leak
next dev/index page works./plugin-page - Server Code leaks to browser (Module not found: Can't resolve 'fs/promises')/component-page - Server Code leaks to browser (Module not found: Can't resolve 'fs/promises')Only the getServerSideProps function in the pages directory works with server code.
Re-exporting a page, whether within the same application package or an external/workspace package (e.g. plugin), leaks server code to the browser.
The docs state a fix, which has already been used to reproduce the issue: https://nextjs.org/docs/messages/export-all-in-page#possible-ways-to-fix-it (export { default, getServerSideProps } from "@repo/page-plugin/pages/index"; )
Operating System:
Platform: win32
Arch: x64
Version: Windows 11 Home
Available memory (MB): 16294
Available CPU cores: 12
Binaries:
Node: 24.11.1
npm: 11.6.2
Yarn: N/A
pnpm: 9.0.0
Relevant Packages:
next: 16.1.0 // Latest available version is detected (16.1.0).
eslint-config-next: N/A
react: 19.2.3
react-dom: 19.2.3
typescript: N/A
Next.js Config:
output: N/A
Pages Router
next dev (local)
No response
Claim this issue to let others know you're working on it. You'll earn 20 points when you complete it!