Title: `@sentry/nuxt` 11: CommonJS packages inlined for build-time instrumentation break in the Nitro bundle · Issue #24775 · getsentry/sentry-javascript · GitHub
Open Graph Title: `@sentry/nuxt` 11: CommonJS packages inlined for build-time instrumentation break in the Nitro bundle · Issue #24775 · getsentry/sentry-javascript
X Title: `@sentry/nuxt` 11: CommonJS packages inlined for build-time instrumentation break in the Nitro bundle · Issue #24775 · getsentry/sentry-javascript
Description: This issue was written with Claude Opus 5.5 (Anthropic) and reviewed by a human before it was filed. Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have rev...
Open Graph Description: This issue was written with Claude Opus 5.5 (Anthropic) and reviewed by a human before it was filed. Is there an existing issue for this? I have checked for existing issues https://github.com/getse...
X Description: This issue was written with Claude Opus 5.5 (Anthropic) and reviewed by a human before it was filed. Is there an existing issue for this? I have checked for existing issues https://github.com/getse...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/24775
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`@sentry/nuxt` 11: CommonJS packages inlined for build-time instrumentation break in the Nitro bundle","articleBody":"_This issue was written with Claude Opus 5.5 (Anthropic) and reviewed by a human before it was filed._\n\n### Is there an existing issue for this?\n\n- [x] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues\n- [x] I have reviewed the documentation https://docs.sentry.io/\n- [x] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases\n\n### How do you use Sentry?\n\nSentry Saas (sentry.io)\n\n### Which SDK are you using?\n\n@sentry/nuxt\n\n### SDK Version\n\n11.0.0\n\n### Framework Version\n\nNuxt 4.5.2 (nitropack 2.13.4, `node-server` preset)\n\n### Link to Sentry event\n\n_No response_\n\n### Reproduction Example/SDK Setup\n\n`nuxt.config.ts` registers `@sentry/nuxt/module` and does not set `buildTimeInstrumentation`, so build-time instrumentation is on. A `sentry.server.config.ts` exists:\n\n```ts\nimport { init } from \"@sentry/nuxt\";\n\ninit({\n dsn: process.env.NUXT_PUBLIC_SENTRY_DSN,\n // further runtime options (integrations, beforeSend, ...) omitted; they don't affect bundling\n});\n```\n\n### Steps to Reproduce\n\nObserved in our project build. The minimal reproduction below has **not** been run on its own.\n\n1. Create a Nuxt 4 app and install `@sentry/nuxt@11.0.0` and `mongoose@9.10.2`.\n2. Add `modules: [\"@sentry/nuxt/module\"]` to `nuxt.config.ts` and create a `sentry.server.config.ts` that calls `Sentry.init({ dsn: \"...\" })`.\n3. Use mongoose in server code that gets bundled, e.g. `server/plugins/db.ts`:\n ```ts\n import mongoose from \"mongoose\";\n export default defineNitroPlugin(() => {\n console.log(mongoose.version);\n });\n ```\n4. `nuxt build`\n5. `node .output/server/index.mjs` (we used Node.js 26)\n6. For the second failure (see Actual Result), apply the `requireReturnsDefault` workaround below, rebuild, and have the plugin `await mongoose.connect(uri)` to a MongoDB user with `?authSource=admin&authMechanism=SCRAM-SHA-1`. We reproduced this with our project build against a local `mongo:8`.\n\n### Expected Result\n\nThe server starts and connects to MongoDB.\n\n### Actual Result\n\nThe server throws while `chunks/nitro/nitro.mjs` is being evaluated, so it never starts listening:\n\n```\nTypeError: mquery is not a constructor\n at file:///app/.output/server/chunks/nitro/nitro.mjs:97168:21\n```\n\nThe failing statement is mongoose's top-level `Query.prototype = new mquery();`.\n\nWith that one worked around (`requireReturnsDefault`, see below), the server logs `Listening`, but the app's startup plugin can't connect to MongoDB. The error is raised in the SCRAM-SHA-1 path of the handshake. Staging log, abridged; a local build of the same commit against a `mongo:8` with `authMechanism=SCRAM-SHA-1` gives the same trace:\n\n```\nApplication startup error MongoRuntimeError: Node.js crypto module is required for SCRAM-SHA-1 authentication\n at passwordDigest (file:///app/.output/server/chunks/nitro/nitro.mjs:55292:16)\n ...\n [cause]: ReferenceError: require is not defined\n at passwordDigest (file:///app/.output/server/chunks/nitro/nitro.mjs:55289:10)\n```\n\n### Additional Context\n\n**Cause**\n\nIn 11.0.0, `setupOrchestrion()` adds every name in `INSTRUMENTED_MODULE_NAMES` (among them `mongoose`, `mongodb` and `ioredis`) plus `standard-as-callback` to `nitro.externals.inline`. These packages are CommonJS, and most of their CommonJS dependencies stay external (`mquery`, `kareem`, `mpath`, `ms`, `sift`, `denque`, `cluster-key-slot` and `@ioredis/commands` are all in `.output/server/node_modules`).\n\nNitro configures `@rollup/plugin-commonjs` with `esmExternals: (id) => !id.startsWith(\"unenv/\")` and `requireReturnsDefault: \"auto\"`. So each `require()` of an external from bundled CommonJS code becomes:\n\n```js\nimport * as mquery$1 from 'mquery';\nconst require$$N = /*@__PURE__*/getDefaultExportFromNamespaceIfNotNamed(mquery$1);\n```\n\n`getDefaultExportFromNamespaceIfNotNamed` only unwraps `default` if it is the **only** key:\n\n```js\nfunction getDefaultExportFromNamespaceIfNotNamed (n) {\n\treturn n && Object.prototype.hasOwnProperty.call(n, 'default') && Object.keys(n).length === 1 ? n['default'] : n;\n}\n```\n\nSince Node.js v23.0.0 (nodejs/node#53848), CommonJS namespaces also carry a `'module.exports'` export next to `default`, so the check never passes for a CommonJS package:\n\n```js\nObject.keys(await import('mquery')); // [ 'default', 'module.exports' ] (Node.js 26.2.0)\n```\n\nNode builtins fail the check too, because their namespaces have named exports. The bundled code therefore gets the namespace object instead of `module.exports`. The comment on `IORedisDependencies` in `packages/nuxt/src/vite/orchestrion.ts` describes this exact problem (\"Leaving it external makes Nitro resolve the default export as a namespace object\"), but the fix there only covers `standard-as-callback`.\n\n**What breaks in our bundle**\n\nEvery package below receives the namespace. Whether that breaks depends on how the bundled code uses it.\n\n| Package | Required by | Use in bundled code | Effect |\n| --- | --- | --- | --- |\n| `mquery` 6.0.0 | mongoose 9.10.2 | `new mquery()` at module top level | crash at startup (observed) |\n| `kareem` 3.4.0 | mongoose | `new Kareem()` | would throw |\n| `mpath` 0.9.0 | mongoose | `mpath.get(...)`, `mpath.set(...)` (namespace has only `default` and `module.exports`) | would throw |\n| `ms` 2.1.3 | mongoose | `ms(val)` | would throw |\n| `sift` 17.1.3 | mongoose | `require('sift').default` | works (`.default` on the namespace is `module.exports`) |\n| `denque` 2.1.0 | ioredis 6.0.0 | `new Deque()` | would throw |\n| `cluster-key-slot` 1.1.1 | ioredis | `calculateSlot(key)` | would throw |\n| `@ioredis/commands` 2.0.0 | ioredis | `.exists`, `.getKeyIndexes`, `.hasFlag`, `.list` (all detected as named exports) | works |\n| `assert` (builtin) | redis-errors 1.2.0 (bundled) | `assert(buffer)` in the `ParserError` constructor | would throw `assert is not a function`; ioredis 6.0.0 never constructs `ParserError` |\n\nOnly the `mquery` crash was observed, because it happens first. The \"would throw\" rows follow from calling or constructing a namespace object. `redis-errors` is bundled because Nitro's string matchers are prefix matches, so the inlined name `redis` also matches `redis-errors`. `events` and `stream` also resolve to namespaces, but our bundle only reads properties from them (`.EventEmitter`, `once`, `.Readable`, `.Writable`).\n\n**Second effect: `require()` inside `try` stays a bare `require`**\n\nBy default (`ignoreTryCatch: true`, not overridden by Nitro), `@rollup/plugin-commonjs` leaves a `require()` of an external module inside a `try` block unconverted, because such calls usually load optional dependencies. Builtins count as external. Nitro emits ESM, where `require` is not defined, so each such call throws a `ReferenceError` and ends up in the surrounding `catch`. mongodb 7.6.0 loads the `crypto` builtin this way in `passwordDigest()`, which it only calls for SCRAM-SHA-1; SCRAM-SHA-256 doesn't reach it. Abridged from `lib/cmap/auth/scram.js`:\n\n```js\nlet nodeCrypto;\ntry {\n nodeCrypto = require('crypto');\n}\ncatch (e) {\n throw new error_1.MongoRuntimeError('Node.js crypto module is required for SCRAM-SHA-1 authentication', { cause: e });\n}\n```\n\nWith 10.75.1, nothing in our config inlined mongodb (orchestrion was opt-in, and we set no `externals.inline`), so mongodb was loaded from `node_modules` as CommonJS, where `require` exists.\n\nWithout the `ignoreTryCatch` setting, our bundle has ten bare `require()` calls inside `try`:\n\n- mongodb: `crypto` (above), plus the optional peer dependencies in `lib/deps.js`, which are `kerberos`, `@mongodb-js/zstd`, `@aws-sdk/credential-providers`, `gcp-metadata`, `snappy`, `socks` and `mongodb-client-encryption`. `socks` 2.8.10 and `gcp-metadata` 9.0.4 are installed in our `.output/server/node_modules`, but the bundled mongodb can't load them.\n- mongoose (`lib/tracing.js`) and ioredis (`built/tracing.js`): a fallback `require('node:diagnostics_channel')`. It is only reached when `process.getBuiltinModule` is missing, so it doesn't run on Node.js 26.\n\n**Regression**\n\nOur previous release used `@sentry/nuxt` 10.75.1 with the same Nuxt 4.5.2, nitropack 2.13.4, `@rollup/plugin-commonjs` 29.0.3, ioredis 6.0.0 and mongoose 9.10.1 (also with mquery 6.0.0), and it deployed and started. In 10.75.1, `setupOrchestrion` only ran with `_experimental.useDiagnosticsChannelInjection`, which we never set. The 11.0.0 release also updated other dependencies; we did not bisect.\n\n**Workaround**\n\nIn `nuxt.config.ts`, use the default export for builtins and for the external CommonJS dependencies:\n\n```ts\nimport { isBuiltin } from \"node:module\";\n\nconst EXTERNAL_COMMONJS_REQUIRES = new Set([\n \"@ioredis/commands\", \"cluster-key-slot\", \"denque\", \"kareem\", \"mpath\", \"mquery\", \"ms\", \"sift\",\n]);\n\nexport default defineNuxtConfig({\n nitro: {\n commonJS: {\n requireReturnsDefault: (id) =>\n isBuiltin(id) || EXTERNAL_COMMONJS_REQUIRES.has(id) ? true : \"auto\",\n // Convert builtin require()s inside try blocks to imports; optional packages stay unresolved.\n ignoreTryCatch: (id) => !isBuiltin(id),\n },\n },\n});\n```\n\n`sift` and `@ioredis/commands` work either way and are listed only to keep the list complete. With both settings, the built `chunks/nitro/nitro.mjs` imports all eight packages as default imports. None of its remaining `getDefaultExportFromNamespaceIfNotNamed` calls wraps a CommonJS external. mongodb's `require('crypto')` becomes `import … from 'crypto'`. The seven optional `require()`s in mongodb's `lib/deps.js` stay bare, so those packages still behave as not installed. Against the same local `mongo:8` (`authMechanism=SCRAM-SHA-1`), this build starts, authenticates (mongod logs `Successfully authenticated`, mechanism `SCRAM-SHA-1`) and serves requests.\n\nThe workaround is validated in our staging deployment (Node.js 26, `node:26-slim` image, a real MongoDB deployment, Redis). The release with both settings starts, passes the deployment's health checks and serves traffic. Two earlier releases failed there: the one with neither setting failed with the `mquery` error, and the one with only `requireReturnsDefault` failed with the SCRAM error.\n\n**Possible fixes (suggestions, not tested)**\n\n- Extend `IORedisDependencies` to cover the CommonJS dependencies of every force-inlined package. Builtins can't be inlined, so they would stay affected.\n- Have `setupOrchestrion()` set `nitro.commonJS.requireReturnsDefault` (as a function) to return `true` for builtins and for the CommonJS externals that force-inlined packages `require()`. This also covers builtins.\n- For `require()` inside `try` in inlined packages: convert builtins via `ignoreTryCatch`, or give the inlined code a real `require` (e.g. `createRequire(import.meta.url)`) so that optional dependencies that are installed can still load.\n\nEither way, a hand-maintained list goes stale when an instrumented package gains a new CommonJS dependency.\n\n### Priority\n\n\u003csub>React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding `+1` or `me too`, to help us triage it.\u003c/sub>\n","author":{"url":"https://github.com/Anton-Honda","@type":"Person","name":"Anton-Honda"},"datePublished":"2026-09-27T11:48:05Z","url":"https://github.com/getsentry/sentry-javascript/issues/24775"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d2e007f7-9b92-e08a-bcc1-be7545f20998 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AF36:2BE37C:1D0A8C9:2615226:6B0412A2 |
| html-safe-nonce | d8e3cc149419cdba917228e72e927faf1ef98cc9afe15451a189980013398e2b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRjM2OjJCRTM3QzoxRDBBOEM5OjI2MTUyMjY6NkIwNDEyQTIiLCJ2aXNpdG9yX2lkIjoiMTg3MTI1NTE4MTc5NTI2NzIzNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 80f5610c2a17cb2f6f150bca8f9481ceed458dfba53f81fe1a5a5a13aae4b401 |
| hovercard-subject-tag | issue:5602379749 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/24775/issue_layout |
| twitter:image | https://opengraph.githubassets.com/36e2eb950096b3efea1abf740aef9803d8c9438df1857650228d4d9dfb1bf490/getsentry/sentry-javascript/issues/24775 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/36e2eb950096b3efea1abf740aef9803d8c9438df1857650228d4d9dfb1bf490/getsentry/sentry-javascript/issues/24775 |
| og:image:alt | This issue was written with Claude Opus 5.5 (Anthropic) and reviewed by a human before it was filed. Is there an existing issue for this? I have checked for existing issues https://github.com/getse... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Anton-Honda |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width