@nuxt/docs-nightly 5.0.0-29807919.2cbde35e → 5.0.0-29809859.f0ca99e9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -386,8 +386,6 @@ The `nitropack` package has been renamed to `nitro`. All import paths have chang
386
386
  | `nitropack/runtime` | `nitro` |
387
387
  | `h3` (for server utilities) | `nitro/h3` |
388
388
 
389
- Auto-imports within server routes (`defineEventHandler`, `getQuery`, `readBody`, `useRuntimeConfig`, etc.) continue to work without changes.
390
-
391
389
  If you have explicit imports in server code, update them:
392
390
 
393
391
  ```diff
@@ -400,12 +398,53 @@ If you have explicit imports in server code, update them:
400
398
  ```diff
401
399
  - declare module 'nitropack/types' {
402
400
  + declare module 'nitro/types' {
403
- interface NitroRouteRules {
401
+ interface NitroRuntimeConfig {
404
402
  myModule?: { /* ... */ }
405
403
  }
406
404
  }
407
405
  ```
408
406
 
407
+ Route rules are augmented on a different module again. See [Route Rule Types Move to `h3/rules`](#route-rule-types-move-to-h3rules).
408
+
409
+ #### Server Auto-Imports Are Now Opt-In
410
+
411
+ Nitro v3 removed its auto-import support, so utilities such as `defineEventHandler`, `getQuery`, `readBody` and `useRuntimeConfig` are no longer global in server code. Nuxt still provides them, but in Nuxt 5 they are off by default.
412
+
413
+ Add explicit imports to your server code:
414
+
415
+ ```diff [server/api/hello.ts]
416
+ + import { defineEventHandler, getQuery } from 'nitro/h3'
417
+ +
418
+ export default defineEventHandler((event) => {
419
+ return getQuery(event)
420
+ })
421
+ ```
422
+
423
+ Or keep the previous behaviour while you migrate:
424
+
425
+ ```ts [nuxt.config.ts]
426
+ export default defineNuxtConfig({
427
+ experimental: {
428
+ nitroAutoImports: true,
429
+ },
430
+ })
431
+ ```
432
+
433
+ This applies only to the utilities Nitro and h3 provide. Your own exports from `server/utils/` and `shared/utils/` are still auto-imported.
434
+
435
+ #### `#imports` Is Deprecated in Server Code, in Favour of `#imports/server`
436
+
437
+ Server code should import from `#imports/server`:
438
+
439
+ ```diff [server/api/hello.ts]
440
+ - import { defineEventHandler } from '#imports'
441
+ + import { defineEventHandler } from '#imports/server'
442
+
443
+ export default defineEventHandler(() => ({ hello: true }))
444
+ ```
445
+
446
+ `#imports` still resolves when your server code runs, so an unmigrated project keeps working, but it is no longer typed: TypeScript reports it as unresolved until you move to `#imports/server`.
447
+
409
448
  #### Error Handling: `status`/`statusText` replace `statusCode`/`statusMessage`
410
449
 
411
450
  h3 v2 renames the error properties to align with Web standards:
@@ -513,9 +552,70 @@ If you define redirect route rules, the property name has changed:
513
552
  })
514
553
  ```
515
554
 
555
+ Nuxt applies `statusCode` as `status` for now and warns, so an unmigrated rule keeps its status rather than silently falling back to the default. The fallback will be removed.
556
+
557
+ #### Cached Route Rules Ignore Query Parameters
558
+
559
+ Cached routes (`cache`, `swr`, `isr`) now key on the path only, and the query string is dropped before the handler runs. Set `allowQuery` to keep it, either as `true` or as a list of parameter names:
560
+
561
+ ```ts
562
+ export default defineNuxtConfig({
563
+ routeRules: {
564
+ '/products': { cache: { swr: true, maxAge: 60, allowQuery: ['page'] } },
565
+ },
566
+ })
567
+ ```
568
+
569
+ #### Route Rule Types Move to `h3/rules`
570
+
571
+ Nitro v3 builds route rules on h3, so custom route rules are declared there rather than on `nitro/types`. `NitroRouteConfig` and `NitroRouteRules` are still exported as deprecated aliases, but they are now type aliases rather than interfaces, so augmenting them fails with `TS2300: Duplicate identifier`.
572
+
573
+ There are two interfaces to declare, and they are separate on purpose. `RouteRuleConfig` is what a rule looks like in `nuxt.config`, and `RouteRules` is what a matched rule looks like at runtime:
574
+
575
+ ```diff
576
+ - declare module 'nitropack/types' {
577
+ - interface NitroRouteConfig {
578
+ + declare module 'h3/rules' {
579
+ + interface RouteRuleConfig {
580
+ myModule?: { enabled: boolean }
581
+ }
582
+ - interface NitroRouteRules {
583
+ + interface RouteRules {
584
+ myModule?: { enabled: boolean }
585
+ }
586
+ }
587
+ ```
588
+
589
+ A rule that nothing declares now reads back as `unknown` rather than `any`, so it needs a cast at the point of use:
590
+
591
+ ```diff
592
+ - const enabled = rules.myUndeclaredRule
593
+ + const enabled = rules.myUndeclaredRule as boolean | undefined
594
+ ```
595
+
596
+ #### The Server `tsconfig.json` Is Generated by Nuxt
597
+
598
+ Nuxt now generates `.nuxt/tsconfig.server.json` itself, as one of the tsconfigs it writes per environment, rather than delegating it to the server builder. If you extended it through Nitro, use the Nuxt option instead:
599
+
600
+ ```diff
601
+ export default defineNuxtConfig({
602
+ - nitro: {
603
+ - typescript: {
604
+ - tsConfig: { compilerOptions: { /* ... */ } },
605
+ - },
606
+ - },
607
+ + typescript: {
608
+ + serverTsConfig: { compilerOptions: { /* ... */ } },
609
+ + },
610
+ })
611
+ ```
612
+
613
+ `typescript.serverTsConfig` already existed in Nuxt 4 and was kept in sync with `nitro.typescript.tsConfig`, so this is a no-op if you were already using it.
614
+
516
615
  #### For Module Authors: Additional Changes
517
616
 
518
- - **Nitro plugin imports**: Use `import { definePlugin } from 'nitro'` for explicit imports (auto-imports still work).
617
+ - **Nitro plugin imports**: Use `import { definePlugin } from 'nitro'`, which is now required by default. See [Server Auto-Imports Are Now Opt-In](#server-auto-imports-are-now-opt-in).
618
+ - **Route rule helpers**: `basicAuth` route rules are replaced by middleware, and a new `cors` rule replaces manual CORS wiring. See the [Nitro migration guide](https://nitro.build/docs/migration) for the runtime details.
519
619
  - **Runtime hooks**: `nitroApp.hooks.hook('beforeResponse', ...)` and `nitroApp.hooks.hook('afterResponse', ...)` have been replaced by `nitroApp.hooks.hook('response', ...)`.
520
620
  - **`getRouteRules()` from `nitro/app`**: On the server, the Nitro helper changed from `getRouteRules(event)` to `getRouteRules(method, pathname)`, which returns `{ routeRules }`.
521
621
 
@@ -144,9 +144,9 @@ export default defineNuxtModule({
144
144
  interface MyModuleNitroRules {
145
145
  myModule?: { foo: 'bar' }
146
146
  }
147
- declare module 'nitro/types' {
148
- interface NitroRouteRules extends MyModuleNitroRules {}
149
- interface NitroRouteConfig extends MyModuleNitroRules {}
147
+ declare module 'h3/rules' {
148
+ interface RouteRules extends MyModuleNitroRules {}
149
+ interface RouteRuleConfig extends MyModuleNitroRules {}
150
150
  }
151
151
  export {}`,
152
152
  })
@@ -141,7 +141,7 @@ function extendRouteRules (route: string, rule: NitroRouteConfig, options?: Exte
141
141
  ### Parameters
142
142
 
143
143
  **route**: A route pattern to match against.\
144
- **rule**: A route rule configuration to apply to the matched route.
144
+ **rule**: A route rule configuration to apply to the matched route. `NitroRouteConfig` is a union of `NitroRouteConfigV2` and `NitroRouteConfigV3`, so a rule has to be valid for one Nitro major as a whole. A few rules differ between them: Nitro v3 takes `redirect: { status }` where v2 takes `redirect: { statusCode }`, and v3 additionally accepts CORS options on `cors` and `false` on `redirect`/`proxy` to reset an inherited rule.
145
145
 
146
146
  ::tip
147
147
  About route rules configurations, you can get more detail in [Hybrid Rendering > Route Rules](/docs/4.x/guide/concepts/rendering#route-rules).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/docs-nightly",
3
- "version": "5.0.0-29807919.2cbde35e",
3
+ "version": "5.0.0-29809859.f0ca99e9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",