diff --git a/content/blog/50.v4-7.md b/content/blog/50.v4-7.md new file mode 100644 index 000000000..66b32fc91 --- /dev/null +++ b/content/blog/50.v4-7.md @@ -0,0 +1,564 @@ +--- +title: Nuxt 4.7 +description: Nuxt 4.7 lets you try Nitro v3, adds experimental WebMCP support, shows type and lint problems in the dev overlay and validates runtime config. +image: /assets/blog/v4.7.png +authors: + - username: danielroe + name: Daniel Roe +date: 2026-11-23T00:00:00.000Z +category: Release +--- + +Nuxt 4.7 is out, with around 350 commits since v4.6.4. 🎉 + +It's a release with something for everyone. You can try out Nitro v3, offer your app's actions to AI agents in the browser, see type errors and lint warnings right next to your runtime errors, and validate your runtime config with a schema. And it should be even faster, especially for server rendering, hydration and installs. + +## 📣 Some News + +### Try Nitro v3 Today + +The biggest thing in this release is that you can now build your Nuxt 4 app with [Nitro v3](https://nitro.build) ([#37101](https://github.com/nuxt/nuxt/pull/37101)). Nitro v3 is what Nuxt 5 is built on, so this is a way to move your server code (and your modules) over before you upgrade Nuxt itself. + +There's no config to change. Add `nitro` to your dependencies: + +::code-group{sync="pm"} + +```bash [npm] +npm install nitro +``` + +```bash [yarn] +yarn add nitro +``` + +```bash [pnpm] +pnpm add nitro +``` + +```bash [bun] +bun add nitro +``` + +```bash [deno] +deno add npm:nitro +``` + +:: + +If `nitro` is in your `package.json`, Nuxt builds with Nitro v3. To go back, just remove it. + +![nuxt build with Nitro v3](/assets/blog/v4-7/nitro-v3-build-dark.png) + +::caution +This is **highly experimental**. Nitro v3 is still a release candidate, and there are no guarantees. Please try it on a branch, not in production. 🙏 +:: + +Do give Nitro v3 a try! On our benchmark app with about 170 pages, the same app on 4.7 served 33% more requests per second on its home page with Nitro v3 than with Nitro v2 (926 to 1,236), and 44% more on a page with 1,000 links (219 to 316), with identical HTML. + +Most Nuxt 4 apps (and the modules they use) were written for Nitro v2 and h3 v1. So, on Nuxt 4, Nitro v3 runs with a compatibility layer called `nitroLegacy`. It keeps imports from `h3`, `nitropack` and `#imports` resolving, keeps the Nitro v2 auto-imports, `useRuntimeConfig(event)`, `event.node` and the Nitro v2 hooks working, and keeps a long list of h3 v1 behaviours, from `sendRedirect` ending the response to the `cache-control` headers cached routes send. + +Once things are working, turn the layer off to find the code that still depends on it: + +```ts [nuxt.config.ts] +export default defineNuxtConfig({ + nitroLegacy: false, +}) +``` + +A few things change with Nitro v3 regardless. The main one is route rules: Nitro v3 matches them with [a different pattern syntax](/docs/getting-started/upgrade#route-rule-patterns), so `/blog/*` now also applies to `/blog/2026/hello`. Nuxt warns about each rule whose meaning changes, and stops on a rule that uses more than one wildcard (like `/api/*/items/**`), which you can rewrite with a named parameter (`/api/:id/items/**`). Your app matches route rules the same way as the server, so Nuxt-only route rules like `appMiddleware` and `ssr` apply to the same paths on both. + +The other is imports. If your server code imported a package your app didn't depend on, Nitro v2 fell back to Nuxt's own dependencies. Nitro v3 doesn't, so `nuxt dev` fails with something like `Cannot find package 'ufo'`. Make sure every package your server code imports is in your `package.json`. + +::read-more{to="/docs/getting-started/upgrade#testing-nitro-v3"} +Read the full list of what changes with Nitro v3 on Nuxt 4. +:: + +If something breaks for you (and it might), please [open an issue](https://github.com/nuxt/nuxt/issues/new/choose) and mention Nitro v3. Every report helps make the move to Nuxt 5 smoother for everyone. ❤️ + +### Nuxt CLI 4.1 + +Nuxt 4.7 also comes with [Nuxt CLI 4.1](https://github.com/nuxt/cli/releases/tag/v4.1.0). + +The most visible change is in `nuxt build`. Instead of printing each tool's logs one after the other, the CLI now renders the whole production build itself from a set of new build hooks ([nuxt/cli#1662](https://github.com/nuxt/cli/pull/1662), [#37194](https://github.com/nuxt/nuxt/pull/37194)). Thanks to [@atinux](https://github.com/atinux) for this one. ❤️ It works the same way with every builder (Vite, webpack, Rspack, Rsbuild) and every server builder (Nitro v2, Nitro v3 and `@nuxt/vite-server`): + +![nuxt build in Nuxt 4.7 with Nuxt CLI 4.1](/assets/blog/v4-7/build-after-dark.png) + +`nuxt generate` shows the prerendered routes in the same way, and ends by suggesting where to deploy: + +![nuxt generate listing prerendered routes](/assets/blog/v4-7/prerender-after-dark.png) + +There's more: + +- `nuxt dev --https` serves over HTTP/2, so the browser loads the modules of a page in parallel on a single connection, thanks to [@ProgramRipper](https://github.com/ProgramRipper) ([nuxt/cli#1694](https://github.com/nuxt/cli/pull/1694)) +- you can click and scroll inside the panes of the dev panel, thanks to [@Flo0806](https://github.com/Flo0806) ([nuxt/cli#1665](https://github.com/nuxt/cli/pull/1665)) +- copying a URL or an error works without a system clipboard (for example over SSH, or in a container), as long as your terminal supports it ([nuxt/cli#1693](https://github.com/nuxt/cli/pull/1693)) +- new `nuxt module build` and `nuxt module prepare` commands for module authors ([nuxt/cli#1687](https://github.com/nuxt/cli/pull/1687)), paving the way for `@nuxt/module-builder` v2, built on `tsdown` with support for TypeScript 7.1 (watch this space!) +- logs from Nuxt and modules stay inside the build output rather than breaking out of it ([nuxt/cli#1705](https://github.com/nuxt/cli/pull/1705)) +- a route that fails to prerender is listed with the pages that link to it, with [nitropack v2.14](https://github.com/nitrojs/nitro-v2/releases/tag/v2.14.0) ([#37245](https://github.com/nuxt/nuxt/pull/37245)) + +## 🤖 WebMCP (Experimental) + +[WebMCP](https://webmachinelearning.github.io/webmcp/) is a proposed browser API that lets a page offer _tools_ to AI agents running in the browser. That means an agent can add something to a cart or submit a form without guessing which button to click. + +This started from [@sdras](https://github.com/sdras)'s proposal for Vue and WebMCP, and much of the shape of it comes from her work and feedback ([#37195](https://github.com/nuxt/nuxt/pull/37195)). Thank you, Sarah! 💚 + +```ts [nuxt.config.ts] +export default defineNuxtConfig({ + experimental: { + webmcp: true, + }, +}) +``` + +Most of what an agent needs is already bound in your templates, so tagging a function with `@tool` is enough: + +```vue [app/pages/index.vue] + + + +``` + +This registers an `add_to_cart` tool. The arguments come from the template, so an agent can only do what a user could click, and it can't run while the button is disabled. Inside a `v-for`, the `:key` becomes a `target` the agent picks, and a shared `list_targets` tool lists what's on screen. + +A `@tool` bound to `@submit` becomes a form tool. Its input is the form's `v-model` bindings, and a call fills in the form and submits it for real, so your own validation and submit handler run just as they would for a person: + +```vue [app/pages/contact.vue] + + +