Skip to content

fix(nuxt): Stop importing h3 in the Nitro error hook - #24283

Merged
s1gr1d merged 5 commits into
developfrom
t3code/9c33bc1e
Sep 17, 2026
Merged

s1gr1d merged 5 commits into
developfrom
t3code/9c33bc1e

Conversation

@s1gr1d

@s1gr1d s1gr1d commented Sep 10, 2026

Copy link
Copy Markdown
Member

Nuxt 5 switched on its Nitro v2 compatibility layer for any module whose server code imports h3: nuxt/nuxt#36318

The hook now recognizes h3 errors the way h3 itself does, without importing it: h3 v2 by the error's name, h3 v1 by the static __h3_error__ flag on the class. Both expose statusCode.

Our CI tests currently show this warning:

[WebServer] [warn] [NUXT_B9003] Nitro v2 compatibility was applied to server code from 1 module, because of what it imports:
[WebServer]   - `@sentry/nuxt/module` (imports `h3`)
[WebServer] ╰▶ fix: This layer is transitional and will be removed in Nuxt 6. Update the module to import from `nuxt/server`, registering the portable file alongside the one it ships today, or report it to the module author if the module is not your own.

@github-actions

github-actions Bot commented Sep 10, 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.14 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.78 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 39.63 kB - -
@sentry/core/browser 13.66 kB - -
@sentry/node 132.37 kB +0.02% +17 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.03 kB - -
@sentry/node - without tracing 89.82 kB +0.04% +31 B 🔺
@sentry/node - without channel injection 111.23 kB +0.02% +19 B 🔺
@sentry/aws-serverless 98.06 kB +0.03% +25 B 🔺
@sentry/cloudflare (withSentry) - minified 204.52 kB - -
@sentry/cloudflare (withSentry) 508.73 kB - -

View base workflow run

@s1gr1d

s1gr1d commented Sep 10, 2026

Copy link
Copy Markdown
Member Author

This still fails, but because of another issue.

Cannot find module 'ofetch' imported from 'virtual:nuxt:.nuxt%2Ffetch.server.mjs'
  at fetchModule (vite@8.2.2/dist/node/chunks/node.js:34330:32)
  at FetchableDevEnvironment.fetchModule (nitro@3.0.260903-beta/dist/_build/vite.dev.mjs:51:17)

That's probably an upstream issue.
It's Nitro's dev Vite environment failing to resolve a bare ofetch from a virtual module, under pnpm isolation where ofetch only exists as a transitive dep of nuxt.

Created a PR to add ofetch as explicit dependency for now: #24304

s1gr1d added a commit that referenced this pull request Sep 10, 2026
@s1gr1d
s1gr1d marked this pull request as ready for review September 10, 2026 13:56
@s1gr1d
s1gr1d requested a review from a team as a code owner September 10, 2026 13:56
@s1gr1d
s1gr1d requested review from mydea and nicohrubec and removed request for a team September 10, 2026 13:56
Comment thread packages/nuxt/src/runtime/utils/captureError.ts Outdated
@s1gr1d
s1gr1d requested a review from JPeer264 September 14, 2026 11:37
*/
export default (nitroApp => {
// @ts-expect-error Nitro v3 hands the `error` hook an `HTTPEvent`, Nitro v2 an `H3Event`
nitroApp.hooks.hook('error', sentryCaptureErrorHook);

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/q: Can't we do a function overload then?

@s1gr1d s1gr1d Sep 17, 2026

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.

This is also connected to the differences of nitro and nitropack but I can rework the function so there's no h3 import needed. And then we also don't need the expect-error.

@@ -0,0 +1,12 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { H3Error } from 'h3';

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: Why can't we simply move it to nitro/h3 entirely? Then we could keep everything in one function

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.

No, this does not work on Nuxt 3 and 4 because they don't ship nitro but nitropack. That's why we need different files and a proxy.

Comment thread packages/nuxt/src/runtime/hooks/captureErrorHook.ts Outdated
@s1gr1d s1gr1d changed the title fix(nuxt): Split the Nitro error hook as Nuxt 5 stops importing h3 fix(nuxt): Stop importing h3 in the Nitro error hook Sep 17, 2026
Comment thread packages/nuxt/src/runtime/hooks/captureErrorHook.ts
@s1gr1d
s1gr1d merged commit c94fd11 into develop Sep 17, 2026
634 of 636 checks passed
@s1gr1d
s1gr1d deleted the t3code/9c33bc1e branch September 17, 2026 15:18
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