fix(nuxt): Stop importing h3 in the Nitro error hook - #24283
Conversation
size-limit report 📦
|
|
This still fails, but because of another issue. That's probably an upstream issue. Created a PR to add |
Related to this comment: #24283 (comment)
| */ | ||
| export default (nitroApp => { | ||
| // @ts-expect-error Nitro v3 hands the `error` hook an `HTTPEvent`, Nitro v2 an `H3Event` | ||
| nitroApp.hooks.hook('error', sentryCaptureErrorHook); |
There was a problem hiding this comment.
l/q: Can't we do a function overload then?
There was a problem hiding this comment.
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'; | |||
There was a problem hiding this comment.
q: Why can't we simply move it to nitro/h3 entirely? Then we could keep everything in one function
There was a problem hiding this comment.
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.
Nuxt 5 switched on its Nitro v2 compatibility layer for any module whose server code imports
h3: nuxt/nuxt#36318The 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 exposestatusCode.Our CI tests currently show this warning: