Skip to content

fix(build): externalize Next server packages#2100

Open
NathanDrake2406 wants to merge 1 commit into
cloudflare:mainfrom
NathanDrake2406:nathan/prerender-native-module
Open

fix(build): externalize Next server packages#2100
NathanDrake2406 wants to merge 1 commit into
cloudflare:mainfrom
NathanDrake2406:nathan/prerender-native-module

Conversation

@NathanDrake2406

Copy link
Copy Markdown
Contributor

Summary

  • Add Next.js's default server-external package list and merge it with serverExternalPackages plus user ssr.external entries.
  • Apply the shared externalization policy to Node Pages Router builds, App Router RSC/SSR builds, and App Router client optimizer excludes while preserving bundled Cloudflare/Nitro behavior.
  • Port the relevant prerender-native-module Pages Router behavior with a local sqlite/sqlite3 fixture that proves native sqlite3 stays external and that prerendered/fallback routes render the same props contract.

Root Cause

Vinext forced most Node server dependencies through Vite with noExternal: true, only letting React and ipaddr.js escape in plain Pages Router builds. Packages like sqlite3 therefore got bundled into the ESM server entry, where CommonJS/native-loader code can retain __dirname and crash during build-time prerendering.

Next.js keeps a predefined server external package list and combines it with user serverExternalPackages; packages on that effective list are loaded natively instead of bundled.

References

Verification

  • vp test run tests/build-optimization.test.ts --project unit -t "server packages"
  • vp test run tests/nextjs-compat/prerender-native-module.test.ts --project integration
  • vp check packages/vinext/src/index.ts packages/vinext/src/config/server-external-packages.ts tests/build-optimization.test.ts tests/nextjs-compat/prerender-native-module.test.ts
  • vp env exec --node 24 ./scripts/run-nextjs-deploy-suite.sh /Users/nathan/Projects/vinext/.refs/nextjs-v16.2.6 --retries 0 -c 1 --debug test/e2e/prerender-native-module.test.ts

Pre-commit also ran staged checks, full check, staged unit/integration tests, and knip successfully.

@pkg-pr-new

pkg-pr-new Bot commented Jun 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@vinext/cloudflare@2100
npm i https://pkg.pr.new/vinext@2100

commit: efa6454

@NathanDrake2406 NathanDrake2406 marked this pull request as ready for review June 17, 2026 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant