Skip to content

fix(server-runtime-injection): Keep require() of JSON working on Deno - #24409

Closed
isaacs wants to merge 2 commits into
developfrom
isaacs/deno-require-json
Closed

isaacs wants to merge 2 commits into
developfrom
isaacs/deno-require-json

Conversation

@isaacs

@isaacs isaacs commented Sep 16, 2026

Copy link
Copy Markdown
Member

Deno's nextLoad reports no module format for a .json file, where Node reports 'json'. With any load hook installed, Deno's CJS loader then compiles the JSON as JavaScript, so require() of it throws SyntaxError: Unexpected token ':'. A pass-through Module.registerHooks({ resolve, load }) reproduces this with no Sentry code involved, on both Deno 2.8.3 and 2.9.6.

That made @sentry/deno/import (as a first import or as a --preload) crash any app whose dependency graph requires JSON. redis and ioredis both do, through @ioredis/commands.

Restoring the format in our load wrapper is enough. Node never reports a missing format, so the wrapper only applies on Deno.

@isaacs
isaacs requested review from a team as code owners September 16, 2026 00:58
@isaacs
isaacs requested review from JPeer264 and mydea and removed request for a team September 16, 2026 00:58
@isaacs
isaacs added this pull request to stack #24410 September 16, 2026 00:58
@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.09 kB - -
@sentry/browser - with treeshaking flags 27.35 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.26 kB - -
@sentry/browser (incl. Tracing) 50.6 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 50.62 kB - -
@sentry/browser (incl. Tracing, Profiling) 53.61 kB - -
@sentry/browser (incl. Tracing, Replay) 90.15 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 79.25 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 94.85 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 107.83 kB - -
@sentry/browser (incl. Feedback) 46.62 kB - -
@sentry/browser (incl. sendFeedback) 34.15 kB - -
@sentry/browser (incl. FeedbackAsync) 39.26 kB - -
@sentry/browser (incl. Metrics) 30.1 kB - -
@sentry/browser (incl. Logs) 30.35 kB - -
@sentry/browser (incl. Metrics & Logs) 31.02 kB - -
@sentry/react 30.84 kB - -
@sentry/react (incl. Tracing) 52.94 kB - -
@sentry/vue 36.34 kB - -
@sentry/vue (incl. Tracing) 52.91 kB - -
@sentry/svelte 29.11 kB - -
CDN Bundle 30.8 kB - -
CDN Bundle (incl. Tracing) 51.15 kB - -
CDN Bundle (incl. Logs, Metrics) 33.06 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 53.09 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.75 kB - -
CDN Bundle (incl. Tracing, Replay) 88.69 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 90.63 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 94.73 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 96.71 kB - -
CDN Bundle - uncompressed 91.16 kB - -
CDN Bundle (incl. Tracing) - uncompressed 152.66 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 97.73 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 158.61 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 227.14 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 272.23 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 278.17 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 285.93 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 291.86 kB - -
@sentry/nextjs (client) 55.27 kB - -
@sentry/sveltekit (client) 51.05 kB - -
@sentry/core/server 37.13 kB - -
@sentry/core/browser 13.66 kB - -
@sentry/node 132.26 kB +0.05% +65 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.08 kB +0.07% +56 B 🔺
@sentry/node - without tracing 89.89 kB +0.09% +78 B 🔺
@sentry/node - without channel injection 111.08 kB +0.02% +12 B 🔺
@sentry/aws-serverless 98.12 kB +0.06% +56 B 🔺
@sentry/cloudflare (withSentry) - minified 203.54 kB - -
@sentry/cloudflare (withSentry) 506.83 kB - -

View base workflow run

@isaacs
isaacs marked this pull request as draft September 16, 2026 03:13
isaacs and others added 2 commits September 15, 2026 20:55
Deno's `nextLoad` reports no module format for a `.json` file, where
Node reports `'json'`. With any load hook installed, Deno's CJS loader
then compiles the JSON as JavaScript, so `require()` of it throws
`SyntaxError: Unexpected token ':'`. A pass-through
`Module.registerHooks({ resolve, load })` reproduces this with no Sentry
code involved, on both Deno 2.8.3 and 2.9.6.

That made `@sentry/deno/import` (as a first import or as a `--preload`)
crash any app whose dependency graph requires JSON. `redis` and
`ioredis` both do, through `@ioredis/commands`.

Restoring the format in our load wrapper is enough. Node never reports a
missing format, so the wrapper only applies on Deno.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@isaacs
isaacs force-pushed the isaacs/deno-require-json branch from baf860d to c7e9f4f Compare September 16, 2026 03:58
@isaacs
isaacs marked this pull request as ready for review September 16, 2026 04:00
@isaacs isaacs closed this Sep 16, 2026
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