Skip to content

fix(pages): preserve CJS globals in bundled dependencies - #2826

Draft
james-elicx wants to merge 1 commit into
mainfrom
codex/fix-pages-bundled-cjs-globals
Draft

fix(pages): preserve CJS globals in bundled dependencies#2826
james-elicx wants to merge 1 commit into
mainfrom
codex/fix-pages-bundled-cjs-globals

Conversation

@james-elicx

@james-elicx james-elicx commented Aug 6, 2026

Copy link
Copy Markdown
Member

Summary

  • preserve CommonJS __dirname and __filename semantics when Pages dependencies are converted for the Node dev module runner
  • cover both explicitly optimized dependencies and on-demand CommonJS conversion without enabling global dependency discovery
  • respect Node package-scope type: module boundaries and avoid App Router, client, Cloudflare, and Nitro paths
  • leave production bundling chunk-relative and relocatable, matching a real Next.js webpack Pages build

Regression coverage

  • a real Pages route imports a node_modules CommonJS dependency that reads both globals and a sibling asset
  • disabling the injectors fails in dev with ReferenceError: __dirname is not defined
  • explicit optimizer-include and on-demand paths both pass with dependency discovery still disabled
  • a relocated production build must resolve relative to the copied server chunk and reject build-host/node_modules paths

Validation

  • focused Pages dev, optimizer, virtual-entry timing, and relocated-production fixture tests
  • tests/import-meta-url.test.ts
  • tests/build-optimization.test.ts
  • touched-file vp check
  • independent review: clean after removing a non-relocatable production source-path transform and global optimizer crawl

@pkg-pr-new

pkg-pr-new Bot commented Aug 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@vinext/cloudflare@2826
npm i https://pkg.pr.new/create-vinext-app@2826
npm i https://pkg.pr.new/@vinext/types@2826
npm i https://pkg.pr.new/vinext@2826

commit: cb39205

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor
Example Preview Production Original
app-router-cloudflare preview production
pages-router-cloudflare preview production
app-router-playground preview production original
realworld-api-rest preview production
nextra-docs-template preview production
benchmarks preview production
hackernews preview production original
workers-cache preview production
web preview production

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Performance benchmarks

Compared cb39205 against base 3c5cea4 using alternating same-runner rounds. Next.js was unchanged and skipped.

1 improved · 0 regressed · 5 within ±1.5%

Scenario Framework Baseline Current Change
Client bundle size (gzip) vinext 134.6 KB 134.6 KB ⚫ +0.0%
Client entry size (gzip) vinext 122.1 KB 122.2 KB ⚫ +0.0%
Dev server cold start vinext 2.93 s 2.88 s 🟢 -1.7%
Production build time vinext 3.09 s 3.07 s ⚫ -0.5%
RSC entry closure size (gzip) vinext 113.8 KB 113.9 KB ⚫ +0.0%
Server bundle size (gzip) vinext 191.4 KB 191.4 KB ⚫ +0.0%

View detailed results and traces

🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head

@james-elicx
james-elicx force-pushed the codex/fix-pages-bundled-cjs-globals branch from 69dfc6e to 0a4cfb8 Compare August 6, 2026 10:25
@james-elicx
james-elicx force-pushed the codex/fix-pages-bundled-cjs-globals branch from 0a4cfb8 to cb39205 Compare August 6, 2026 10:38
@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues

@ask-bonk

ask-bonk Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

UnknownError: ProviderInitError

github run

@ask-bonk

ask-bonk Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

@james-elicx Bonk workflow failed. Check the logs for details.

View workflow run · To retry, trigger Bonk again.

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