Skip to content

fix(server-runtime-injection): Keep ES modules working on Deno - #24669

Open
JPeer264 wants to merge 1 commit into
jp/node-suites-bunfrom
jp/node-suites-deno-esm-fix
Open

JPeer264 wants to merge 1 commit into
jp/node-suites-bunfrom
jp/node-suites-deno-esm-fix

Conversation

@JPeer264

@JPeer264 JPeer264 commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

With deno run --preload=npm:@sentry/deno/import, an instrumented library that ships an ES module build crashed on import with ReferenceError: require is not defined. Deno's module hooks report no format for an ES module, so the orchestrion transform treated it as CommonJS and injected a require() into it. This hit the ESM builds of the AI SDKs and postgres, among others.

The Deno load hook now restores the format of .mjs files and of .js files in a "type": "module" package, the same way it already did for JSON (#24412). It restores it on the nextLoad result, because the transform reads the format there.

Running the shared Node integration suites on Deno found this. The next PR in the stack runs them in CI; the Deno-only orchestrion suites did not catch it because they publish fake channel messages instead of loading the real libraries.

Part of #24052 and #23897.

🤖 Generated with Claude Code

@linear-code

linear-code Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

JS-3587

JS-3523

@JPeer264
JPeer264 added this pull request to stack #24670 September 23, 2026 16:19
@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.24 kB - -
@sentry/browser - with treeshaking flags 27.5 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.4 kB - -
@sentry/browser (incl. Tracing) 51.15 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 51.17 kB - -
@sentry/browser (incl. Tracing, Profiling) 54.18 kB - -
@sentry/browser (incl. Tracing, Replay) 90.76 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 79.86 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 95.46 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 108.41 kB - -
@sentry/browser (incl. Feedback) 46.76 kB - -
@sentry/browser (incl. sendFeedback) 34.3 kB - -
@sentry/browser (incl. FeedbackAsync) 39.41 kB - -
@sentry/browser (incl. Metrics) 30.25 kB - -
@sentry/browser (incl. Logs) 30.51 kB - -
@sentry/browser (incl. Metrics & Logs) 31.18 kB - -
@sentry/react 31 kB - -
@sentry/react (incl. Tracing) 53.45 kB - -
@sentry/vue 36.74 kB - -
@sentry/vue (incl. Tracing) 53.7 kB - -
@sentry/svelte 29.26 kB - -
CDN Bundle 30.93 kB - -
CDN Bundle (incl. Tracing) 51.69 kB - -
CDN Bundle (incl. Logs, Metrics) 33.2 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 53.66 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.92 kB - -
CDN Bundle (incl. Tracing, Replay) 89.28 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 91.25 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 95.45 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 97.42 kB - -
CDN Bundle - uncompressed 91.4 kB - -
CDN Bundle (incl. Tracing) - uncompressed 153.77 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 97.97 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 159.73 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 227.54 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 273.5 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 279.44 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 287.2 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 293.13 kB - -
@sentry/nextjs (client) 55.77 kB - -
@sentry/sveltekit (client) 51.59 kB - -
@sentry/core/server 39.95 kB - -
@sentry/core/browser 13.63 kB - -
@sentry/node 136.74 kB +0.08% +107 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.74 kB +0.22% +178 B 🔺
@sentry/node - without tracing 90.68 kB +0.12% +107 B 🔺
@sentry/node - without channel injection 115.09 kB +0.01% +9 B 🔺
@sentry/aws-serverless 98.94 kB +0.1% +94 B 🔺
@sentry/cloudflare (withSentry) - minified 206.49 kB - -
@sentry/cloudflare (withSentry) 513.73 kB - -

View base workflow run

@JPeer264
JPeer264 force-pushed the jp/node-suites-deno-esm-fix branch from 055e26b to 540f4fe Compare September 23, 2026 16:40
@JPeer264 JPeer264 self-assigned this Sep 23, 2026
@JPeer264
JPeer264 removed this pull request from stack #24670 September 23, 2026 17:26
@JPeer264
JPeer264 added this pull request to stack #24671 September 23, 2026 17:31
@JPeer264
JPeer264 marked this pull request as ready for review September 23, 2026 17:35
@JPeer264
JPeer264 requested a review from a team as a code owner September 23, 2026 17:35
@JPeer264
JPeer264 requested review from andreiborza, isaacs, logaretm and stephanie-anderson and removed request for a team, logaretm and stephanie-anderson September 23, 2026 17:35
@JPeer264
JPeer264 force-pushed the jp/node-suites-deno-esm-fix branch from 540f4fe to c909f07 Compare September 24, 2026 09:13
@JPeer264
JPeer264 force-pushed the jp/node-suites-deno-esm-fix branch from c909f07 to 29a2d60 Compare September 24, 2026 09:24
@JPeer264
JPeer264 force-pushed the jp/node-suites-deno-esm-fix branch from 29a2d60 to 12e0fce Compare September 24, 2026 14:05
@JPeer264
JPeer264 force-pushed the jp/node-suites-deno-esm-fix branch 2 times, most recently from 3197ab3 to 65bccc8 Compare September 25, 2026 15:41
@JPeer264
JPeer264 requested a review from a team as a code owner September 25, 2026 15:41
Deno's module hooks report no `format` for an ES module, so the
orchestrion transform treated it as CommonJS and injected a `require()`
that throws when the module loads. This broke `@sentry/node` on Deno for
the ESM builds of libraries it instruments, such as the AI SDKs and
`postgres`. The Deno load hook now restores the format of `.mjs` files
and of `.js` files in a `"type": "module"` package, the same way it
already did for JSON.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JPeer264
JPeer264 force-pushed the jp/node-suites-deno-esm-fix branch from 65bccc8 to 0991af4 Compare September 25, 2026 15:49

@isaacs isaacs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is straightforwardly correct. Closes the loop that we started with the JSON fix. TBH, I'm not sure why we didn't do that then. Oh well, probably thought we could get away without the added overhead.

Definitely add a comment to remove it in v12 (or 13 or whenever Deno ages out of needing it).

* `'json'` or `'module'`. Without the format, Deno's CJS loader compiles JSON as JavaScript
* (`SyntaxError: Unexpected token ':'`), and the transform treats an ES module as CommonJS and
* injects a `require()` into it (`ReferenceError: require is not defined`). The format is restored
* on the `nextLoad` result, so the transform sees it too. Only Deno needs this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth adding a comment here and in the PR description as well, that it's only needed as long as we support Deno versions that do not have the fix in denoland/deno#36849.

We're already gating on the presence/lack of a format, so we don't need any version sniffing, I don't think. But it'd be nice to know when we can cut the fix out entirely, certainly not before v12.

Actually, come to think of it, could also add a // todo(v12): evaluate if this is still needed for supported Deno versions so we know to circle back.

This branch has not been deployed

No deployments
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.

2 participants