Nitro v3 under Nuxt 4.7: The One-Line Opt-In
Build a Nuxt 4.7 app with Nitro v3 by adding one dependency. Read the nitroLegacy layer, fix route-rule patterns and undeclared imports, and turn the layer off to find the code that still depends on Nitro v2.
This is the release's real headline. Nuxt 5 will run on Nitro v3. Nuxt 4.7 lets you run it now.
What's new#
If nitro is in your package.json, Nuxt builds with Nitro v3. If nitropack is there instead, it builds with Nitro v2. If both are present, Nuxt picks v3. Remove nitro and you are back on v2.
pnpm add nitro
That is the whole switch. Your app code does not change, and you do not need to touch server.builder.
Why you'd care#
Nitro v3 is not a point release. It is h3 v2, web-standard Request/Response, srvx, a compiled router, a much smaller install, and a different set of defaults. Nuxt 5 is built on it. Testing it on 4.7 means the migration happens on a minor you can roll back.
The numbers are real: on Nuxt's benchmark app with about 170 pages, the same app served 33% more requests per second on the home page (926 → 1,236) and 44% more on a page with 1,000 links (219 → 316), with identical HTML.
Before#
A Nuxt 4.6 app imports defineEventHandler and friends from auto-imports that resolve to h3 v1. Server code reaches through event.node.req, and route rules use glob patterns that match one segment.
After#
The same app on Nitro v3 runs with a compatibility layer called nitroLegacy, on by default. It keeps:
- imports from
h3,nitropack, and#importsresolving; - the Nitro v2 auto-imports;
useRuntimeConfig(event),event.node, and the Nitro v2 hooks;- a long list of h3 v1 behaviours, from
sendRedirectending the response to thecache-controlheaders cached routes send.
The layer is a diagnostic tool, not a destination. Turn it off:
export default defineNuxtConfig({
nitroLegacy: false,
});
Now the errors are honest. In most apps they are imports:
Cannot find package 'ufo' imported from .nuxt/dev/index.mjs
Nitro v2 quietly resolved packages from Nuxt's own dependency tree. Nitro v3 does not. Add every package your server code imports to your package.json.
Route rules changed#
Nitro v3 matches route rules with rou3, not the old glob matcher. The differences that matter:
- A single
*matches any number of segments, so/blog/*also applies to/blog/2026/hello. **followed by more pattern requires the rest, so/docs/**/editmatches/docs/intro/editbut not/docs/intro.- A parameter name ends at the first character that is not a letter, digit, or
_./users/:user-idis:userfollowed by-id. - A catch-all does not match an empty segment, so
/files/a//bdoes not match/files/:path+.
Nuxt warns about each rule whose meaning changes (NUXT_B4029) and stops on a rule with more than one wildcard. Rewrite the ambiguous ones with named parameters.
Do it yourself#
- Create a branch.
pnpm add nitro.pnpm devand click through the app.- Fix the route-rule warnings.
- Add the packages your server imports.
- Set
nitroLegacy: false. - Fix what the errors find.
- Run
pnpm build.
If something breaks, open an issue and mention Nitro v3. Every report helps the Nuxt 5 migration.
Gotchas#
- Nitro v3 is a release candidate. Pin the version you tested. Do not ship this to production on a Friday.
nitroLegacyhides the work. Turning it off is the point. If you leave it on forever, you have not migrated; you have postponed.- Route rules apply to the app and the server. A rule whose meaning changed can affect
ssr,redirect,appMiddleware,appLayout,noScripts, and payload extraction. Review the scope, not just the build warning. - Server responses differ.
event.resis the h3 v2 response (event.res.headers,event.res.status), not Node's response.event.res.setHeader()is gone. - Runtime config is converted, not cast. Environment variables become the type of the value they replace. A number-looking string is a number, and a bad value stops the boot.
- Cached routes ignore query parameters by default. Nitro v3 caches
/page?a=1and/page?utm=xunder one key. UseallowQueryif that is wrong for your route.
Recap#
Nitro v3 under Nuxt is one dependency and one compatibility layer. Add nitro, fix the route rules and imports, then turn the layer off. You have just done most of the Nuxt 5 server migration on 4.7.
Next: WebMCP.