Repository navigation
feat(node): Publish flat CJS builds to cut @sentry/node startup time - #25968
Conversation
size-limit report 📦Compared: 101f0ce (PR test merge using develop at a72b2d8) Against: a72b2d8 (develop) · base run #65953 ✅ Baseline matches: this diff contains only this PR's changes.
|
|
One or more gzipped bundles increased by more than 500 bytes. If this increase is intentional, add the Accept Bundlesize Increase label to this PR to rerun and accept the check. |
Optional E2E testsSome optional checks were not successful. They do not block the merge. 4 not successful, 56 successful. See the run.
Successful checks
|
03ae48a to
b61e94d
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b61e94d. Configure here.
|
Hmm, flattening ESM breaks tree-shaking. Trying with just flattening CJS only, see if that's a bit nicer. |
bdf1180 to
29a8cd2
Compare
@sentry/node startup time@sentry/node startup time
|
Updated PR description to match CJS-only approach. |
|
So this effectively turns off Maybe it was affecting browser bundles a bit more, I'm working on rolldown migration and the same thing popped up there. Not blocking this, just wondering if u have noticed potential tree-shaking issues.
EDIT: Oh, yep this is what I was referring to. So you are only doing it for CJS which seems to not affect tree-shaking. |
timfish
left a comment
There was a problem hiding this comment.
I'm all for this but the Rolldown PR should get merged and pulled in here first!
nicohrubec
left a comment
There was a problem hiding this comment.
rolldown pr was merged yesterday so this should be ready for a final rebase?
`require('@sentry/node')` loaded 606 CommonJS files and took about
95 ms. Most of that time went to resolving, reading and evaluating many
small files, because each source file was a published file.
The CJS builds of `@sentry/core`, `@sentry/node`, `@sentry/server-utils`
and `@sentry/server-runtime-injection` now publish one file per entry,
plus shared chunks with fixed names. `require('@sentry/node')` now loads
70 files in about 52 ms.
The ESM builds keep one file per module. Bundlers use them, and drop
unused files by the package's `sideEffects` setting. Flat ESM files
made the Next.js edge build fail on `node:` imports in code it never
used, and grew the server bundles in the size check by up to 140%.
Each package keeps its `@sentry/*` dependencies external, so no package
carries a second copy of another. Rolldown puts a module in a chunk by
the set of entries that reach it, so build-time code stays out of the
runtime entries, and runtime injection stays out of the build-time
ones.
In the flat CJS build of `@sentry/server-runtime-injection`, the
vendored loader hook chain is in `chunks/hook.js`. Both `register.js`
and `hook.js` require it, so a tracer that ships `register.js` still
ships everything the hook needs. The nft trace test now checks for that
chunk instead of the old `vendored/` path.
The Lambda layer build now finds the `getSDKSource` marker by searching
the core build, because the flat CJS build has no `utils/env.js`. Two
cloudflare tests lose their mocks of that old CJS path.
A new test caps the files each Sentry package loads when Node requires
`@sentry/node`. The runtime-entries test now also checks that
build-time entries do not reach runtime injection. Three config entries
already do, through the `@sentry/node` and `@sentry/nitro` roots, and
are known violations.
Closes #25680
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ea4ff6d to
ff5087c
Compare

require('@sentry/node')loaded 606 CommonJS files and took about95 ms. Most of that time went to resolving, reading and evaluating many
small files, because each source file was a published file.
The CJS builds of
@sentry/core,@sentry/node,@sentry/server-utilsand
@sentry/server-runtime-injectionnow publish one file per entry,plus shared chunks with fixed names.
require('@sentry/node')now loads70 files in about 52 ms.
The ESM builds keep one file per module. Bundlers use them, and drop
unused files by the package's
sideEffectssetting. Flat ESM filesmade the Next.js edge build fail on
node:imports in code it neverused, and grew the server bundles in the size check by up to 140%.
Each package keeps its
@sentry/*dependencies external, so no packagecarries a second copy of another. Rolldown puts a module in a chunk by
the set of entries that reach it, so build-time code stays out of the
runtime entries, and runtime injection stays out of the build-time
ones.
In the flat CJS build of
@sentry/server-runtime-injection, thevendored loader hook chain is in
chunks/hook.js. Bothregister.jsand
hook.jsrequire it, so a tracer that shipsregister.jsstillships everything the hook needs. The nft trace test now checks for that
chunk instead of the old
vendored/path.The Lambda layer build now finds the
getSDKSourcemarker by searchingthe core build, because the flat CJS build has no
utils/env.js. Twocloudflare tests lose their mocks of that old CJS path.
A new test caps the files each Sentry package loads when Node requires
@sentry/node. The runtime-entries test now also checks thatbuild-time entries do not reach runtime injection. Three config entries
already do, through the
@sentry/nodeand@sentry/nitroroots, andare known violations.
Closes #25680