Repository navigation
fix(server-runtime-injection): Register the CJS loader hook from the CJS build - #26278
Conversation
…CJS build On Node < 24.13 the CJS build passed build/esm/hook.js to Module.register(). Turbopack ships that file but not the files it imports, so registration failed in Next.js standalone output. The CJS build now registers build/cjs/hook.js. That file only requires chunks that register.js requires too, so every tracer ships them. The loader that forced the ESM format for build/esm is no longer needed.
size-limit report 📦Compared: f8134e0 (PR test merge using develop at 621a801) Against: 621a801 (develop) · base run #65856 ✅ Baseline matches: this diff contains only this PR's changes.
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 76cccea. Configure here.
… files register.js requires
Optional E2E testsSome optional checks were not successful. They do not block the merge. 4 not successful, 46 successful. See the run.
Successful checks
|
isaacs
left a comment
There was a problem hiding this comment.
Compared with #26271, this is smaller, has fewer moving parts, and does not bring in the debug browser code or the 3.5 MB source map. Its one weak point was that it depended on a chunking fact no test checked. The second commit now checks that for the CJS build, which is the build Next.js loads. I would prefer this PR over #26271. After a CI re-run, and with the test cleanups, it is ready to land.
Co-authored-by: isaacs <i@izs.me>
…ory in the hook test The copy is made in beforeAll under os.tmpdir(), so a killed run leaves no duplicate package in the repo. The child script reads the marker directly, because Module.register() throws on the main thread. Also fixes a doubled word in the hook.mjs comment.
…from the hook entry With rolldown, export * emitted a build/cjs/hook.js that read an undefined import_diagnostics binding, so the CJS hook failed to load. Module.register() only reads initialize, load and resolve, so the entry now exports those three.

On Node < 24.13, the CJS build of
register.tspassedbuild/esm/hook.jstoModule.register(). Turbopack ships that file in the Next.js server trace but does not follow its imports, so the loader thread could not findbuild/esm/vendored/**or the ESM build of@sentry/core. Registration then warned on every cold start.The CJS build now registers
build/cjs/hook.js, which the package already built but did not use. That file only requires chunks thatregister.jsrequires too, so a tracer that ships a workingregister.jsalways ships them. Node accepts a CJS module as aModule.register()target. This is an alternative to #26271: the package does not grow and no Next.js config is needed.The
data:URL loader that forced the ESM format forbuild/esmis removed. It only helped the CJS build load the ESM hook when a deployment droppedbuild/esm/package.json, and the CJS build no longer loads anything frombuild/esm. The ESM build still registers the ESM hook.The new
test/hook.test.tsregisters the hook from a copy that ships onlybuild/cjs. Thenextjs-16-standalonebuild-output test (taken from #26271) forces theModule.register()path against the real Turbopack standalone output. Both fail ondevelopwith the error from the issue.Closes #26121