Skip to content

fix(nuxt): Fix CommonJS interop for force-inlined instrumented packages - #24799

Draft
s1gr1d wants to merge 3 commits into
developfrom
sig/nuxt-mongoose-deps
Draft

s1gr1d wants to merge 3 commits into
developfrom
sig/nuxt-mongoose-deps

Conversation

@s1gr1d

@s1gr1d s1gr1d commented Sep 28, 2026

Copy link
Copy Markdown
Member

Since v11, build-time instrumentation force-inlines the instrumented drivers (mongoose, ioredis, mysql, ...) into the Nitro bundle while their CommonJS dependencies stay external. Since Node 23, CJS namespaces carry a module.exports key next to default (nodejs/node#53848), so Rollup's 'auto' interop no longer unwraps those requires and the drivers crash at startup (mquery is not a constructor).

No single interop mode (a requireReturnsDefault value) fixes this and works for all externals. debug needs the namespace, while mquery and lodash.defaults need module.exports. So we unwrap builtins plus a known list and keep 'auto' for the rest.

Fixes #24775
Fixes #24786

@s1gr1d

s1gr1d commented Sep 28, 2026

Copy link
Copy Markdown
Member Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 02b9d8f. Configure here.

@github-actions

github-actions Bot commented Sep 28, 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.18 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.08 kB - -
@sentry/react (incl. Tracing) 53.54 kB - -
@sentry/vue 36.74 kB - -
@sentry/vue (incl. Tracing) 53.7 kB - -
@sentry/svelte 29.26 kB - -
CDN Bundle 31.02 kB - -
CDN Bundle (incl. Tracing) 51.78 kB - -
CDN Bundle (incl. Logs, Metrics) 33.29 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 53.75 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 74 kB - -
CDN Bundle (incl. Tracing, Replay) 89.37 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 91.34 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 95.53 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 97.5 kB - -
CDN Bundle - uncompressed 91.66 kB - -
CDN Bundle (incl. Tracing) - uncompressed 154.05 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 98.23 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 160 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 227.8 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 273.78 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 279.72 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 287.48 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 293.41 kB - -
@sentry/nextjs (client) 55.78 kB - -
@sentry/sveltekit (client) 51.6 kB - -
@sentry/core/server 39.99 kB - -
@sentry/core/browser 13.63 kB - -
@sentry/node 142.24 kB +0.01% +7 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.88 kB - -
@sentry/node - without tracing 91.25 kB +0.02% +10 B 🔺
@sentry/node - without channel injection 120.64 kB +0.01% +6 B 🔺
@sentry/aws-serverless 99.52 kB +0.01% +5 B 🔺
@sentry/cloudflare (withSentry) - minified 206.64 kB - -
@sentry/cloudflare (withSentry) 514.04 kB - -

View base workflow run

@JPeer264 JPeer264 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.

Overall LGTM, just got one bigger concern.

name: 'save blogposts',
status: 'ok',
is_segment: false,
attributes: expect.objectContaining({

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.

l: Maybe you could apply our /write-tests skill on these tests, they should actualy remove the expect.objectContaining assertions.

// startup or on first connect.
const UNWRAPPED_DRIVER_DEPENDENCIES = new Set([
// mongoose
'kareem',

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.

q/m: If one of these libs now add/remove any dependency then it would fail again right? Unless we ship a new version. Is there any chance we can keep this up to date without us maintaining this list manually? Since this is inside the bundler we could maybe get the dependency list somehow?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The list is gone now.

But these failures probably come from @rollup/plugin-commonjs: their check probably stopped working on Node 23, because Node now adds an extra 'module.exports' key to imported CommonJS modules (nodejs/node#53848).

So instead of listing every affected package, sentryCommonJSInteropPlugin fixes that one line during the build. Everything then behaves exactly like it did on Node 22.

I also added a PR in the rollup commonjs plugin: rollup/plugins#2027

@s1gr1d
s1gr1d marked this pull request as draft September 29, 2026 15:14

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

2 participants