@nuxt/docs 4.1.2 → 4.2.0

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.
Files changed (201) hide show
  1. package/1.getting-started/01.introduction.md +6 -6
  2. package/1.getting-started/02.installation.md +3 -2
  3. package/1.getting-started/03.configuration.md +36 -36
  4. package/1.getting-started/04.views.md +9 -9
  5. package/1.getting-started/05.assets.md +15 -9
  6. package/1.getting-started/06.styling.md +58 -48
  7. package/1.getting-started/07.routing.md +17 -17
  8. package/1.getting-started/08.seo-meta.md +59 -46
  9. package/1.getting-started/09.transitions.md +49 -44
  10. package/1.getting-started/10.data-fetching.md +104 -81
  11. package/1.getting-started/11.state-management.md +26 -19
  12. package/1.getting-started/12.error-handling.md +22 -20
  13. package/1.getting-started/13.server.md +8 -8
  14. package/1.getting-started/14.layers.md +22 -16
  15. package/1.getting-started/15.prerendering.md +32 -32
  16. package/1.getting-started/16.deployment.md +10 -10
  17. package/1.getting-started/17.testing.md +44 -44
  18. package/1.getting-started/18.upgrade.md +241 -110
  19. package/2.guide/0.index.md +7 -7
  20. package/2.guide/{2.directory-structure → 1.directory-structure}/.navigation.yml +1 -1
  21. package/2.guide/{2.directory-structure → 1.directory-structure}/0.nuxt.md +3 -3
  22. package/2.guide/1.directory-structure/0.output.md +18 -0
  23. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/.navigation.yml +1 -1
  24. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.assets.md +4 -4
  25. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.components.md +45 -28
  26. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.composables.md +13 -13
  27. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.layouts.md +19 -15
  28. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.middleware.md +31 -25
  29. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.pages.md +39 -37
  30. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.plugins.md +25 -25
  31. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.utils.md +7 -7
  32. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.app-config.md +18 -18
  33. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.app.md +7 -7
  34. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.error.md +6 -6
  35. package/2.guide/{2.directory-structure → 1.directory-structure}/1.content.md +7 -4
  36. package/2.guide/{2.directory-structure → 1.directory-structure}/1.modules.md +8 -8
  37. package/2.guide/{2.directory-structure → 1.directory-structure}/1.node_modules.md +2 -2
  38. package/2.guide/{2.directory-structure → 1.directory-structure}/1.public.md +2 -2
  39. package/2.guide/{2.directory-structure → 1.directory-structure}/1.server.md +35 -35
  40. package/2.guide/{2.directory-structure → 1.directory-structure}/1.shared.md +7 -7
  41. package/2.guide/{2.directory-structure → 1.directory-structure}/2.env.md +8 -8
  42. package/2.guide/{2.directory-structure → 1.directory-structure}/2.gitignore.md +1 -1
  43. package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtignore.md +5 -4
  44. package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtrc.md +4 -4
  45. package/2.guide/{2.directory-structure → 1.directory-structure}/3.nuxt-config.md +3 -3
  46. package/2.guide/{2.directory-structure → 1.directory-structure}/3.package.md +1 -1
  47. package/2.guide/{2.directory-structure → 1.directory-structure}/3.tsconfig.md +3 -3
  48. package/2.guide/{1.concepts → 2.concepts}/1.auto-imports.md +22 -22
  49. package/2.guide/{1.concepts → 2.concepts}/10.nuxt-lifecycle.md +17 -17
  50. package/2.guide/{1.concepts → 2.concepts}/2.vuejs-development.md +13 -13
  51. package/2.guide/{1.concepts → 2.concepts}/3.rendering.md +24 -22
  52. package/2.guide/{1.concepts → 2.concepts}/4.server-engine.md +6 -6
  53. package/2.guide/{1.concepts → 2.concepts}/5.modules.md +5 -5
  54. package/2.guide/{1.concepts → 2.concepts}/7.esm.md +22 -16
  55. package/2.guide/{1.concepts → 2.concepts}/8.typescript.md +12 -12
  56. package/2.guide/3.going-further/1.events.md +3 -3
  57. package/2.guide/3.going-further/1.experimental-features.md +334 -85
  58. package/2.guide/3.going-further/1.features.md +58 -11
  59. package/2.guide/3.going-further/1.internals.md +25 -25
  60. package/2.guide/3.going-further/10.runtime-config.md +12 -12
  61. package/2.guide/3.going-further/11.nightly-release-channel.md +1 -1
  62. package/2.guide/3.going-further/2.hooks.md +14 -14
  63. package/2.guide/3.going-further/3.modules.md +126 -108
  64. package/2.guide/3.going-further/4.kit.md +7 -7
  65. package/2.guide/3.going-further/6.nuxt-app.md +8 -8
  66. package/2.guide/3.going-further/7.layers.md +76 -59
  67. package/2.guide/3.going-further/9.debugging.md +2 -2
  68. package/2.guide/4.recipes/1.custom-routing.md +30 -30
  69. package/2.guide/4.recipes/2.vite-plugin.md +45 -4
  70. package/2.guide/4.recipes/3.custom-usefetch.md +13 -13
  71. package/2.guide/4.recipes/4.sessions-and-authentication.md +35 -21
  72. package/2.guide/5.best-practices/hydration.md +4 -4
  73. package/2.guide/5.best-practices/performance.md +17 -17
  74. package/3.api/1.components/1.client-only.md +6 -3
  75. package/3.api/1.components/1.nuxt-client-fallback.md +10 -7
  76. package/3.api/1.components/10.nuxt-picture.md +1 -1
  77. package/3.api/1.components/11.teleports.md +5 -2
  78. package/3.api/1.components/12.nuxt-route-announcer.md +9 -9
  79. package/3.api/1.components/13.nuxt-time.md +49 -18
  80. package/3.api/1.components/2.nuxt-page.md +6 -6
  81. package/3.api/1.components/3.nuxt-layout.md +15 -10
  82. package/3.api/1.components/4.nuxt-link.md +42 -22
  83. package/3.api/1.components/5.nuxt-loading-indicator.md +3 -3
  84. package/3.api/1.components/6.nuxt-error-boundary.md +12 -10
  85. package/3.api/2.composables/on-prehydrate.md +2 -2
  86. package/3.api/2.composables/use-app-config.md +1 -1
  87. package/3.api/2.composables/use-async-data.md +26 -22
  88. package/3.api/2.composables/use-cookie.md +29 -21
  89. package/3.api/2.composables/use-error.md +2 -2
  90. package/3.api/2.composables/use-fetch.md +62 -32
  91. package/3.api/2.composables/use-head-safe.md +7 -7
  92. package/3.api/2.composables/use-head.md +5 -5
  93. package/3.api/2.composables/use-hydration.md +6 -6
  94. package/3.api/2.composables/use-lazy-async-data.md +4 -4
  95. package/3.api/2.composables/use-lazy-fetch.md +4 -4
  96. package/3.api/2.composables/use-loading-indicator.md +12 -12
  97. package/3.api/2.composables/use-nuxt-app.md +22 -22
  98. package/3.api/2.composables/use-nuxt-data.md +8 -8
  99. package/3.api/2.composables/use-preview-mode.md +15 -18
  100. package/3.api/2.composables/use-request-event.md +1 -1
  101. package/3.api/2.composables/use-request-fetch.md +3 -3
  102. package/3.api/2.composables/use-request-header.md +1 -1
  103. package/3.api/2.composables/use-request-headers.md +4 -4
  104. package/3.api/2.composables/use-request-url.md +1 -1
  105. package/3.api/2.composables/use-response-header.md +9 -10
  106. package/3.api/2.composables/use-route-announcer.md +4 -4
  107. package/3.api/2.composables/use-route.md +1 -1
  108. package/3.api/2.composables/use-router.md +10 -8
  109. package/3.api/2.composables/use-runtime-config.md +11 -11
  110. package/3.api/2.composables/use-runtime-hook.md +2 -2
  111. package/3.api/2.composables/use-seo-meta.md +4 -4
  112. package/3.api/2.composables/use-server-seo-meta.md +6 -6
  113. package/3.api/2.composables/use-state.md +5 -5
  114. package/3.api/3.utils/$fetch.md +10 -8
  115. package/3.api/3.utils/abort-navigation.md +3 -3
  116. package/3.api/3.utils/add-route-middleware.md +5 -5
  117. package/3.api/3.utils/call-once.md +6 -6
  118. package/3.api/3.utils/clear-error.md +3 -3
  119. package/3.api/3.utils/clear-nuxt-data.md +3 -3
  120. package/3.api/3.utils/clear-nuxt-state.md +3 -3
  121. package/3.api/3.utils/create-error.md +2 -2
  122. package/3.api/3.utils/define-lazy-hydration-component.md +13 -13
  123. package/3.api/3.utils/define-nuxt-component.md +5 -5
  124. package/3.api/3.utils/define-nuxt-plugin.md +13 -13
  125. package/3.api/3.utils/define-nuxt-route-middleware.md +5 -5
  126. package/3.api/3.utils/define-page-meta.md +23 -23
  127. package/3.api/3.utils/define-route-rules.md +7 -7
  128. package/3.api/3.utils/navigate-to.md +11 -11
  129. package/3.api/3.utils/prefetch-components.md +1 -1
  130. package/3.api/3.utils/preload-components.md +1 -1
  131. package/3.api/3.utils/preload-route-components.md +2 -2
  132. package/3.api/3.utils/prerender-routes.md +3 -3
  133. package/3.api/3.utils/refresh-cookie.md +4 -4
  134. package/3.api/3.utils/refresh-nuxt-data.md +12 -7
  135. package/3.api/3.utils/reload-nuxt-app.md +3 -3
  136. package/3.api/3.utils/set-page-layout.md +1 -1
  137. package/3.api/3.utils/set-response-status.md +3 -3
  138. package/3.api/3.utils/show-error.md +5 -5
  139. package/3.api/3.utils/update-app-config.md +4 -3
  140. package/3.api/4.commands/add.md +1 -1
  141. package/3.api/4.commands/analyze.md +2 -1
  142. package/3.api/4.commands/build.md +2 -1
  143. package/3.api/4.commands/dev.md +5 -4
  144. package/3.api/4.commands/generate.md +3 -2
  145. package/3.api/4.commands/init.md +3 -2
  146. package/3.api/4.commands/module.md +4 -4
  147. package/3.api/4.commands/prepare.md +7 -2
  148. package/3.api/4.commands/preview.md +5 -4
  149. package/3.api/4.commands/test.md +40 -0
  150. package/3.api/4.commands/typecheck.md +5 -3
  151. package/3.api/4.commands/upgrade.md +3 -3
  152. package/3.api/5.kit/1.modules.md +123 -37
  153. package/3.api/5.kit/10.runtime-config.md +1 -1
  154. package/3.api/5.kit/10.templates.md +8 -6
  155. package/3.api/5.kit/11.nitro.md +66 -62
  156. package/3.api/5.kit/12.resolving.md +2 -2
  157. package/3.api/5.kit/14.builder.md +61 -4
  158. package/3.api/5.kit/15.examples.md +5 -7
  159. package/3.api/5.kit/16.layers.md +26 -26
  160. package/3.api/5.kit/3.compatibility.md +14 -14
  161. package/3.api/5.kit/4.autoimports.md +13 -13
  162. package/3.api/5.kit/5.components.md +8 -7
  163. package/3.api/5.kit/6.context.md +3 -3
  164. package/3.api/5.kit/7.pages.md +7 -7
  165. package/3.api/5.kit/8.layout.md +2 -2
  166. package/3.api/5.kit/9.head.md +132 -0
  167. package/3.api/5.kit/9.plugins.md +5 -4
  168. package/3.api/6.advanced/1.hooks.md +5 -5
  169. package/3.api/6.advanced/2.import-meta.md +3 -3
  170. package/3.api/6.nuxt-config.md +365 -859
  171. package/3.api/index.md +7 -7
  172. package/5.community/2.getting-help.md +1 -1
  173. package/5.community/3.reporting-bugs.md +3 -3
  174. package/5.community/4.contribution.md +11 -11
  175. package/5.community/5.framework-contribution.md +4 -4
  176. package/5.community/6.roadmap.md +2 -2
  177. package/6.bridge/1.overview.md +13 -13
  178. package/6.bridge/10.configuration.md +2 -1
  179. package/6.bridge/2.typescript.md +3 -3
  180. package/6.bridge/3.bridge-composition-api.md +8 -8
  181. package/6.bridge/4.plugins-and-middleware.md +9 -9
  182. package/6.bridge/5.nuxt3-compatible-api.md +20 -17
  183. package/6.bridge/6.meta.md +20 -19
  184. package/6.bridge/7.runtime-config.md +1 -1
  185. package/6.bridge/8.nitro.md +3 -3
  186. package/6.bridge/9.vite.md +4 -4
  187. package/7.migration/1.overview.md +2 -2
  188. package/7.migration/10.bundling.md +1 -1
  189. package/7.migration/11.server.md +3 -3
  190. package/7.migration/2.configuration.md +23 -21
  191. package/7.migration/20.module-authors.md +7 -7
  192. package/7.migration/3.auto-imports.md +3 -3
  193. package/7.migration/4.meta.md +21 -18
  194. package/7.migration/5.plugins-and-middleware.md +8 -8
  195. package/7.migration/6.pages-and-layouts.md +28 -24
  196. package/7.migration/7.component-options.md +18 -18
  197. package/7.migration/8.runtime-config.md +7 -7
  198. package/package.json +1 -1
  199. package/2.guide/2.directory-structure/0.output.md +0 -18
  200. /package/2.guide/{1.concepts → 2.concepts}/.navigation.yml +0 -0
  201. /package/2.guide/{1.concepts → 2.concepts}/9.code-style.md +0 -0
@@ -32,7 +32,147 @@ bun x nuxt upgrade
32
32
 
33
33
  ### Nightly Release Channel
34
34
 
35
- To use the latest Nuxt build and test features before their release, read about the [nightly release channel](/docs/guide/going-further/nightly-release-channel) guide.
35
+ To use the latest Nuxt build and test features before their release, read about the [nightly release channel](/docs/4.x/guide/going-further/nightly-release-channel) guide.
36
+
37
+ ## Testing Nuxt 5
38
+
39
+ Nuxt 5 is **currently in development**. Until the release, it is possible to test many of Nuxt 5's breaking changes from Nuxt version 4.2+.
40
+
41
+ ### Opting in to Nuxt 5
42
+
43
+ First, upgrade Nuxt to the [latest release](https://github.com/nuxt/nuxt/releases).
44
+
45
+ Then you can set your `future.compatibilityVersion` to match Nuxt 5 behavior:
46
+
47
+ ```ts twoslash [nuxt.config.ts]
48
+ export default defineNuxtConfig({
49
+ future: {
50
+ compatibilityVersion: 5,
51
+ },
52
+ })
53
+ ```
54
+
55
+ When you set your `future.compatibilityVersion` to `5`, defaults throughout your Nuxt configuration will change to opt in to Nuxt v5 behavior, including:
56
+
57
+ - **Vite Environment API**: Automatically enables the new [Vite Environment API](#migration-to-vite-environment-api) for improved build configuration
58
+ - Other Nuxt 5 improvements and changes as they become available
59
+
60
+ ::note
61
+ This section is subject to change until the final release, so please check back here regularly if you are testing Nuxt 5 using `future.compatibilityVersion: 5`.
62
+ ::
63
+
64
+ Breaking or significant changes will be noted below along with migration steps for backward/forward compatibility.
65
+
66
+ ### Migration to Vite Environment API
67
+
68
+ 🚦 **Impact Level**: Medium
69
+
70
+ #### What Changed
71
+
72
+ Nuxt 5 migrates to Vite 6's new [Environment API](https://vite.dev/guide/api-environment), which formalizes the concept of environments and provides better control over configuration per environment.
73
+
74
+ Previously, Nuxt used separate client and server Vite configurations. Now, Nuxt uses a shared Vite configuration with environment-specific plugins that use the `applyToEnvironment()` method to target specific environments.
75
+
76
+ ::tip
77
+ You can test this feature early by setting `future.compatibilityVersion: 5` (see [Testing Nuxt 5](#testing-nuxt-5)) or by enabling it explicitly with `experimental.viteEnvironmentApi: true`.
78
+ ::
79
+
80
+ **Key changes:**
81
+
82
+ 1. **Deprecated environment-specific `extendViteConfig()`**: The `server` and `client` options in `extendViteConfig()` are deprecated and will show warnings when used.
83
+
84
+ 2. **Changed plugin registration**: Vite plugins registered with `addVitePlugin()` and only targeting one environment (by passing `server: false` or `client: false`) will not have their `config` or `configResolved` hooks called.
85
+
86
+ 3. **Shared configuration**: The `vite:extendConfig` and `vite:configResolved` hooks now work with a shared configuration rather than separate client/server configs.
87
+
88
+ #### Reasons for Change
89
+
90
+ The Vite Environment API provides:
91
+ - Better consistency between development and production builds
92
+ - More granular control over environment-specific configuration
93
+ - Improved performance and plugin architecture
94
+ - Support for custom environments beyond just client and server
95
+
96
+ #### Migration Steps
97
+
98
+ ##### 1. Migrate to use Vite plugins
99
+
100
+ We would recommend you use a Vite plugin instead of `extendViteConfig`, `vite:configResolved` and `vite:extendConfig`.
101
+
102
+ ```ts
103
+ // Before
104
+ extendViteConfig((config) => {
105
+ config.optimizeDeps.include.push('my-package')
106
+ }, { server: false })
107
+
108
+ nuxt.hook('vite:extendConfig' /* or vite:configResolved */, (config, { isClient }) => {
109
+ if (isClient) {
110
+ config.optimizeDeps.include.push('my-package')
111
+ }
112
+ })
113
+
114
+ // After
115
+ addVitePlugin(() => ({
116
+ name: 'my-plugin',
117
+ config (config) {
118
+ // you can set global vite configuration here
119
+ },
120
+ configResolved (config) {
121
+ // you can access the fully resolved vite configuration here
122
+ },
123
+ configEnvironment (name, config) {
124
+ // you can set environment-specific vite configuration here
125
+ if (name === 'client') {
126
+ config.optimizeDeps ||= {}
127
+ config.optimizeDeps.include ||= []
128
+ config.optimizeDeps.include.push('my-package')
129
+ }
130
+ },
131
+ applyToEnvironment (environment) {
132
+ return environment.name === 'client'
133
+ },
134
+ }))
135
+ ```
136
+
137
+ ##### 2. Migrate Vite plugins to use environments
138
+
139
+ Instead of using `addVitePlugin` with `server: false` or `client: false`, you can instead use the new `applyToEnvironment` hook within your plugin.
140
+
141
+ ```ts
142
+ // Before
143
+ addVitePlugin(() => ({
144
+ name: 'my-plugin',
145
+ config (config) {
146
+ config.optimizeDeps.include.push('my-package')
147
+ },
148
+ }), { client: false })
149
+
150
+ // After
151
+ addVitePlugin(() => ({
152
+ name: 'my-plugin',
153
+ config (config) {
154
+ // you can set global vite configuration here
155
+ },
156
+ configResolved (config) {
157
+ // you can access the fully resolved vite configuration here
158
+ },
159
+ configEnvironment (name, config) {
160
+ // you can set environment-specific vite configuration here
161
+ if (name === 'client') {
162
+ config.optimizeDeps ||= {}
163
+ config.optimizeDeps.include ||= []
164
+ config.optimizeDeps.include.push('my-package')
165
+ }
166
+ },
167
+ applyToEnvironment (environment) {
168
+ return environment.name === 'client'
169
+ },
170
+ }))
171
+ ```
172
+
173
+ ::read-more{to="https://vite.dev/guide/api-environment" target="_blank"}
174
+ Learn more about Vite's Environment API
175
+ ::
36
176
 
37
177
  ## Migrating to Nuxt 4
38
178
 
@@ -81,19 +221,23 @@ You can run all the codemods mentioned in this guide using the following `codemo
81
221
  ::code-group
82
222
 
83
223
  ```bash [npm]
84
- npx codemod@latest nuxt/4/migration-recipe
224
+ # Using pinned version due to https://github.com/codemod-com/codemod/issues/1710
225
+ npx codemod@0.18.7 nuxt/4/migration-recipe
85
226
  ```
86
227
 
87
228
  ```bash [yarn]
88
- yarn dlx codemod@latest nuxt/4/migration-recipe
229
+ # Using pinned version due to https://github.com/codemod-com/codemod/issues/1710
230
+ yarn dlx codemod@0.18.7 nuxt/4/migration-recipe
89
231
  ```
90
232
 
91
233
  ```bash [pnpm]
92
- pnpm dlx codemod@latest nuxt/4/migration-recipe
234
+ # Using pinned version due to https://github.com/codemod-com/codemod/issues/1710
235
+ pnpm dlx codemod@0.18.7 nuxt/4/migration-recipe
93
236
  ```
94
237
 
95
238
  ```bash [bun]
96
- bun x codemod@latest nuxt/4/migration-recipe
239
+ # Using pinned version due to https://github.com/codemod-com/codemod/issues/1710
240
+ bun x codemod@0.18.7 nuxt/4/migration-recipe
97
241
  ```
98
242
 
99
243
  ::
@@ -110,11 +254,11 @@ Nuxt now defaults to a new directory structure, with backwards compatibility (so
110
254
 
111
255
  #### What Changed
112
256
 
113
- * the new Nuxt default `srcDir` is `app/` by default, and most things are resolved from there.
114
- * `serverDir` now defaults to `<rootDir>/server` rather than `<srcDir>/server`
115
- * `layers/`, `modules/` and `public/` are resolved relative to `<rootDir>` by default
116
- * if using [Nuxt Content v2.13+](https://github.com/nuxt/content/pull/2649), `content/` is resolved relative to `<rootDir>`
117
- * a new `dir.app` is added, which is the directory we look for `router.options.ts` and `spa-loading-template.html` - this defaults to `<srcDir>/`
257
+ - the new Nuxt default `srcDir` is `app/` by default, and most things are resolved from there.
258
+ - `serverDir` now defaults to `<rootDir>/server` rather than `<srcDir>/server`
259
+ - `layers/`, `modules/` and `public/` are resolved relative to `<rootDir>` by default
260
+ - if using [Nuxt Content v2.13+](https://github.com/nuxt/content/pull/2649), `content/` is resolved relative to `<rootDir>`
261
+ - a new `dir.app` is added, which is the directory we look for `router.options.ts` and `spa-loading-template.html` - this defaults to `<srcDir>/`
118
262
 
119
263
  <details>
120
264
 
@@ -186,8 +330,8 @@ export default defineNuxtConfig({
186
330
  srcDir: '.',
187
331
  // This specifies the directory prefix for `router.options.ts` and `spa-loading-template.html`
188
332
  dir: {
189
- app: 'app'
190
- }
333
+ app: 'app',
334
+ },
191
335
  })
192
336
  ```
193
337
 
@@ -224,14 +368,14 @@ These changes have been made to improve memory usage and increase consistency wi
224
368
  It may be beneficial to extract any calls to `useAsyncData` that share an explicit key (and have custom options) into their own composable:
225
369
 
226
370
  ```ts [app/composables/useUserData.ts]
227
- export function useUserData(userId: string) {
371
+ export function useUserData (userId: string) {
228
372
  return useAsyncData(
229
373
  `user-${userId}`,
230
374
  () => fetchUser(userId),
231
- {
375
+ {
232
376
  deep: true,
233
- transform: (user) => ({ ...user, lastAccessed: new Date() })
234
- }
377
+ transform: user => ({ ...user, lastAccessed: new Date() }),
378
+ },
235
379
  )
236
380
  }
237
381
  ```
@@ -260,8 +404,8 @@ Alternatively, for now, you can disable this behaviour with:
260
404
  export default defineNuxtConfig({
261
405
  experimental: {
262
406
  granularCachedData: false,
263
- purgeCachedData: false
264
- }
407
+ purgeCachedData: false,
408
+ },
265
409
  })
266
410
  ```
267
411
 
@@ -271,7 +415,7 @@ export default defineNuxtConfig({
271
415
 
272
416
  #### What Changed
273
417
 
274
- The order in which modules are loaded when using [Nuxt layers](/docs/guide/going-further/layers) has been corrected. Previously, modules from the project root were loaded before modules from extended layers, which was the reverse of the expected behavior.
418
+ The order in which modules are loaded when using [Nuxt layers](/docs/4.x/guide/going-further/layers) has been corrected. Previously, modules from the project root were loaded before modules from extended layers, which was the reverse of the expected behavior.
275
419
 
276
420
  Now modules are loaded in the correct order:
277
421
 
@@ -279,15 +423,15 @@ Now modules are loaded in the correct order:
279
423
  2. **Project modules last** (highest priority)
280
424
 
281
425
  This affects both:
282
- * Modules defined in the `modules` array in `nuxt.config.ts`
283
- * Auto-discovered modules from the `modules/` directory
426
+ - Modules defined in the `modules` array in `nuxt.config.ts`
427
+ - Auto-discovered modules from the `modules/` directory
284
428
 
285
429
  #### Reasons for Change
286
430
 
287
431
  This change ensures that:
288
- * Extended layers have lower priority than the consuming project
289
- * Module execution order matches the intuitive layer inheritance pattern
290
- * Module configuration and hooks work as expected in multi-layer setups
432
+ - Extended layers have lower priority than the consuming project
433
+ - Module execution order matches the intuitive layer inheritance pattern
434
+ - Module configuration and hooks work as expected in multi-layer setups
291
435
 
292
436
  #### Migration Steps
293
437
 
@@ -303,23 +447,23 @@ Example of the new correct order:
303
447
  ```ts
304
448
  // Layer: my-layer/nuxt.config.ts
305
449
  export default defineNuxtConfig({
306
- modules: ['layer-module-1', 'layer-module-2']
450
+ modules: ['layer-module-1', 'layer-module-2'],
307
451
  })
308
452
 
309
453
  // Project: nuxt.config.ts
310
454
  export default defineNuxtConfig({
311
455
  extends: ['./my-layer'],
312
- modules: ['project-module-1', 'project-module-2']
456
+ modules: ['project-module-1', 'project-module-2'],
313
457
  })
314
458
 
315
459
  // Loading order (corrected):
316
460
  // 1. layer-module-1
317
- // 2. layer-module-2
461
+ // 2. layer-module-2
318
462
  // 3. project-module-1 (can override layer modules)
319
463
  // 4. project-module-2 (can override layer modules)
320
464
  ```
321
465
 
322
- If you encounter issues with module order dependencies due to needing to register a hook, consider using the [`modules:done` hook](/docs/guide/going-further/modules#custom-hooks) for modules that need to call a hook. This is run after all other modules have been loaded, which means it is safe to use.
466
+ If you encounter issues with module order dependencies due to needing to register a hook, consider using the [`modules:done` hook](/docs/4.x/guide/going-further/modules#custom-hooks) for modules that need to call a hook. This is run after all other modules have been loaded, which means it is safe to use.
323
467
 
324
468
  👉 See [PR #31507](https://github.com/nuxt/nuxt/pull/31507) and [issue #25719](https://github.com/nuxt/nuxt/issues/25719) for more details.
325
469
 
@@ -380,8 +524,8 @@ Alternatively, for now, you can disable this behaviour with:
380
524
  ```ts twoslash [nuxt.config.ts]
381
525
  export default defineNuxtConfig({
382
526
  experimental: {
383
- normalizeComponentNames: false
384
- }
527
+ normalizeComponentNames: false,
528
+ },
385
529
  })
386
530
  ```
387
531
 
@@ -394,9 +538,9 @@ export default defineNuxtConfig({
394
538
  [Unhead](https://unhead.unjs.io/), used to generate `<head>` tags, has been updated to version 2. While mostly compatible it includes several breaking changes
395
539
  for lower-level APIs.
396
540
 
397
- * Removed props: `vmid`, `hid`, `children`, `body`.
398
- * Promise input no longer supported.
399
- * Tags are now sorted using Capo.js by default.
541
+ - Removed props: `vmid`, `hid`, `children`, `body`.
542
+ - Promise input no longer supported.
543
+ - Tags are now sorted using Capo.js by default.
400
544
 
401
545
  #### Migration Steps
402
546
 
@@ -404,7 +548,7 @@ The above changes should have minimal impact on your app.
404
548
 
405
549
  If you have issues you should verify:
406
550
 
407
- * You're not using any of the removed props.
551
+ - You're not using any of the removed props.
408
552
 
409
553
  ```diff
410
554
  useHead({
@@ -417,17 +561,17 @@ useHead({
417
561
  })
418
562
  ```
419
563
 
420
- * If you're using [Template Params](https://unhead.unjs.io/docs/head/guides/plugins/template-params) or [Alias Tag Sorting](https://unhead.unjs.io/docs/head/guides/plugins/alias-sorting), you will need to explicitly opt in to these features now.
564
+ - If you're using [Template Params](https://unhead.unjs.io/docs/head/guides/plugins/template-params) or [Alias Tag Sorting](https://unhead.unjs.io/docs/head/guides/plugins/alias-sorting), you will need to explicitly opt in to these features now.
421
565
 
422
566
  ```ts
423
- import { TemplateParamsPlugin, AliasSortingPlugin } from '@unhead/vue/plugins'
567
+ import { AliasSortingPlugin, TemplateParamsPlugin } from '@unhead/vue/plugins'
424
568
 
425
569
  export default defineNuxtPlugin({
426
- setup() {
570
+ setup () {
427
571
  const unhead = injectHead()
428
572
  unhead.use(TemplateParamsPlugin)
429
573
  unhead.use(AliasSortingPlugin)
430
- }
574
+ },
431
575
  })
432
576
  ```
433
577
 
@@ -444,7 +588,7 @@ If you still have issues you may revert to the v1 behavior by enabling the `head
444
588
  export default defineNuxtConfig({
445
589
  unhead: {
446
590
  legacy: true,
447
- }
591
+ },
448
592
  })
449
593
  ```
450
594
 
@@ -483,7 +627,7 @@ Alternatively, you can revert to the previous behaviour with:
483
627
  export default defineNuxtConfig({
484
628
  experimental: {
485
629
  spaLoadingTemplateLocation: 'within',
486
- }
630
+ },
487
631
  })
488
632
  ```
489
633
 
@@ -527,8 +671,8 @@ This feature is fully configurable and you can revert to the previous behavior b
527
671
  ```ts twoslash [nuxt.config.ts]
528
672
  export default defineNuxtConfig({
529
673
  features: {
530
- inlineStyles: true
531
- }
674
+ inlineStyles: true,
675
+ },
532
676
  })
533
677
  ```
534
678
 
@@ -566,8 +710,8 @@ Alternatively, you can revert to the previous behaviour with:
566
710
  ```ts twoslash [nuxt.config.ts]
567
711
  export default defineNuxtConfig({
568
712
  experimental: {
569
- scanPageMeta: true
570
- }
713
+ scanPageMeta: true,
714
+ },
571
715
  })
572
716
  ```
573
717
 
@@ -607,8 +751,8 @@ Alternatively, you can disable this feature with:
607
751
  ```ts twoslash [nuxt.config.ts]
608
752
  export default defineNuxtConfig({
609
753
  experimental: {
610
- sharedPrerenderData: false
611
- }
754
+ sharedPrerenderData: false,
755
+ },
612
756
  })
613
757
  ```
614
758
 
@@ -632,24 +776,6 @@ If you were checking if `data.value` or `error.value` were `null`, you can updat
632
776
  You can automate this step by running `npx codemod@latest nuxt/4/default-data-error-value`
633
777
  ::
634
778
 
635
- If you encounter any issues you can revert back to the previous behavior with:
636
-
637
- ```ts twoslash [nuxt.config.ts]
638
- // @errors: 2353
639
- export default defineNuxtConfig({
640
- experimental: {
641
- defaults: {
642
- useAsyncData: {
643
- value: 'null',
644
- errorValue: 'null'
645
- }
646
- }
647
- }
648
- })
649
- ```
650
-
651
- Please report an issue if you are doing this, as we do not plan to keep this as configurable.
652
-
653
779
  ### Removal of deprecated `boolean` values for `dedupe` option when calling `refresh` in `useAsyncData` and `useFetch`
654
780
 
655
781
  🚦 **Impact Level**: Minimal
@@ -660,7 +786,7 @@ Previously it was possible to pass `dedupe: boolean` to `refresh`. These were al
660
786
 
661
787
  ```ts twoslash [app/app.vue]
662
788
  // @errors: 2322
663
- const { refresh } = await useAsyncData(async () => ({ message: 'Hello, Nuxt!' }))
789
+ const { refresh } = await useAsyncData(() => Promise.resolve({ message: 'Hello, Nuxt!' }))
664
790
 
665
791
  async function refreshData () {
666
792
  await refresh({ dedupe: true })
@@ -748,8 +874,8 @@ Alternatively, you can temporarily revert to the previous behavior with:
748
874
  ```ts twoslash [nuxt.config.ts]
749
875
  export default defineNuxtConfig({
750
876
  experimental: {
751
- pendingWhenIdle: true
752
- }
877
+ pendingWhenIdle: true,
878
+ },
753
879
  })
754
880
  ```
755
881
 
@@ -788,8 +914,8 @@ To opt out of this behavior:
788
914
  // Or globally in your Nuxt config
789
915
  export default defineNuxtConfig({
790
916
  experimental: {
791
- alwaysRunFetchOnKeyChange: true
792
- }
917
+ alwaysRunFetchOnKeyChange: true,
918
+ },
793
919
  })
794
920
  ```
795
921
 
@@ -822,10 +948,10 @@ In most cases, no migration steps are required, but if you rely on the reactivit
822
948
  experimental: {
823
949
  defaults: {
824
950
  useAsyncData: {
825
- deep: true
826
- }
827
- }
828
- }
951
+ deep: true,
952
+ },
953
+ },
954
+ },
829
955
  })
830
956
  ```
831
957
 
@@ -904,10 +1030,10 @@ Probably no migration is necessary but if you wish to revert to previous behavio
904
1030
  ```ts
905
1031
  export default defineNuxtConfig({
906
1032
  hooks: {
907
- 'app:resolve'(app) {
1033
+ 'app:resolve' (app) {
908
1034
  app.middleware = app.middleware.filter(mw => !/\/index\.[^/]+$/.test(mw.path))
909
- }
910
- }
1035
+ },
1036
+ },
911
1037
  })
912
1038
  ```
913
1039
 
@@ -933,9 +1059,9 @@ Finally, providing code serialization functions directly within Nuxt is not idea
933
1059
 
934
1060
  We have raised PRs to update modules using EJS syntax, but if you need to do this yourself, you have three backwards/forwards-compatible alternatives:
935
1061
 
936
- * Moving your string interpolation logic directly into `getContents()`.
937
- * Using a custom function to handle the replacement, such as in https://github.com/nuxt-modules/color-mode/pull/240.
938
- * Use `es-toolkit/compat` (a drop-in replacement for lodash template), as a dependency of _your_ project rather than Nuxt:
1062
+ - Moving your string interpolation logic directly into `getContents()`.
1063
+ - Using a custom function to handle the replacement, such as in https://github.com/nuxt-modules/color-mode/pull/240.
1064
+ - Use `es-toolkit/compat` (a drop-in replacement for lodash template), as a dependency of _your_ project rather than Nuxt:
939
1065
 
940
1066
  ```diff
941
1067
  + import { readFileSync } from 'node:fs'
@@ -957,7 +1083,7 @@ Finally, if you are using the template utilities (`serialize`, `importName`, `im
957
1083
  ```ts
958
1084
  import { genDynamicImport, genImport, genSafeVariableName } from 'knitwork'
959
1085
 
960
- const serialize = (data: any) => JSON.stringify(data, null, 2).replace(/"{(.+)}"(?=,?$)/gm, r => JSON.parse(r).replace(/^{(.*)}$/, '$1'))
1086
+ const serialize = (data: any) => JSON.stringify(data, null, 2).replace(/"\{(.+)\}"(?=,?$)/gm, r => JSON.parse(r).replace(/^\{(.*)\}$/, '$1'))
961
1087
 
962
1088
  const importSources = (sources: string | string[], { lazy = false } = {}) => {
963
1089
  return toArray(sources).map((src) => {
@@ -1002,10 +1128,10 @@ There are two approaches:
1002
1128
  typescript: {
1003
1129
  tsConfig: {
1004
1130
  compilerOptions: {
1005
- noUncheckedIndexedAccess: false
1006
- }
1007
- }
1008
- }
1131
+ noUncheckedIndexedAccess: false,
1132
+ },
1133
+ },
1134
+ },
1009
1135
  })
1010
1136
  ```
1011
1137
 
@@ -1018,11 +1144,11 @@ There are two approaches:
1018
1144
  Nuxt now generates separate TypeScript configurations for different contexts to provide better type-checking experiences:
1019
1145
 
1020
1146
  1. **New TypeScript configuration files**: Nuxt now generates additional TypeScript configurations:
1021
- * `.nuxt/tsconfig.app.json` - For your app code (Vue components, composables, etc.)
1022
- * `.nuxt/tsconfig.server.json` - For your server-side code (Nitro/server directory)
1023
- * `.nuxt/tsconfig.node.json` - For your build-time code (modules, `nuxt.config.ts`, etc.)
1024
- * `.nuxt/tsconfig.shared.json` - For code shared between app and server contexts (like types and non-environment specific utilities)
1025
- * `.nuxt/tsconfig.json` - Legacy configuration for backward compatibility
1147
+ - `.nuxt/tsconfig.app.json` - For your app code (Vue components, composables, etc.)
1148
+ - `.nuxt/tsconfig.server.json` - For your server-side code (Nitro/server directory)
1149
+ - `.nuxt/tsconfig.node.json` - For your build-time code (modules, `nuxt.config.ts`, etc.)
1150
+ - `.nuxt/tsconfig.shared.json` - For code shared between app and server contexts (like types and non-environment specific utilities)
1151
+ - `.nuxt/tsconfig.json` - Legacy configuration for backward compatibility
1026
1152
 
1027
1153
  2. **Backward compatibility**: Existing projects that extend `.nuxt/tsconfig.json` will continue to work as before.
1028
1154
 
@@ -1051,8 +1177,13 @@ However, to take advantage of improved type checking, you can opt in to the new
1051
1177
 
1052
1178
  1. **Update your root `tsconfig.json`** to use project references:
1053
1179
 
1180
+ ::note
1181
+ If your `tsconfig.json` currently has an `"extends": "./.nuxt/tsconfig.json"` line, **remove it** before adding the references. Project references and extends are mutually exclusive.
1182
+ ::
1183
+
1054
1184
  ```json
1055
1185
  {
1186
+ // Remove "extends": "./.nuxt/tsconfig.json" if present
1056
1187
  "files": [],
1057
1188
  "references": [
1058
1189
  { "path": "./.nuxt/tsconfig.app.json" },
@@ -1073,9 +1204,9 @@ However, to take advantage of improved type checking, you can opt in to the new
1073
1204
  ```
1074
1205
 
1075
1206
  4. **Move all type augmentations into their appropriate context**:
1076
- * If you are augmenting types for the app context, move the files to the `app/` directory.
1077
- * If you are augmenting types for the server context, move the files to the `server/` directory.
1078
- * If you are augmenting types that are **shared between the app and server**, move the files to the `shared/` directory.
1207
+ - If you are augmenting types for the app context, move the files to the `app/` directory.
1208
+ - If you are augmenting types for the server context, move the files to the `server/` directory.
1209
+ - If you are augmenting types that are **shared between the app and server**, move the files to the `shared/` directory.
1079
1210
 
1080
1211
  ::warning
1081
1212
  Augmenting types from outside the `app/`, `server/`, or `shared/` directories will not work with the new project references setup.
@@ -1090,16 +1221,16 @@ However, to take advantage of improved type checking, you can opt in to the new
1090
1221
  // Customize app/server TypeScript config
1091
1222
  tsConfig: {
1092
1223
  compilerOptions: {
1093
- strict: true
1094
- }
1224
+ strict: true,
1225
+ },
1095
1226
  },
1096
- // Customize build-time TypeScript config
1227
+ // Customize build-time TypeScript config
1097
1228
  nodeTsConfig: {
1098
1229
  compilerOptions: {
1099
- strict: true
1100
- }
1101
- }
1102
- }
1230
+ strict: true,
1231
+ },
1232
+ },
1233
+ },
1103
1234
  })
1104
1235
  ```
1105
1236
 
@@ -1115,11 +1246,11 @@ The new configuration provides better type safety and IntelliSense for projects
1115
1246
 
1116
1247
  Four experimental features are no longer configurable in Nuxt 4:
1117
1248
 
1118
- * `experimental.treeshakeClientOnly` will be `true` (default since v3.0)
1119
- * `experimental.configSchema` will be `true` (default since v3.3)
1120
- * `experimental.polyfillVueUseHead` will be `false` (default since v3.4)
1121
- * `experimental.respectNoSSRHeader` will be `false` (default since v3.4)
1122
- * `vite.devBundler` is no longer configurable - it will use `vite-node` by default
1249
+ - `experimental.treeshakeClientOnly` will be `true` (default since v3.0)
1250
+ - `experimental.configSchema` will be `true` (default since v3.3)
1251
+ - `experimental.polyfillVueUseHead` will be `false` (default since v3.4)
1252
+ - `experimental.respectNoSSRHeader` will be `false` (default since v3.4)
1253
+ - `vite.devBundler` is no longer configurable - it will use `vite-node` by default
1123
1254
 
1124
1255
  #### Reasons for Change
1125
1256
 
@@ -1127,9 +1258,9 @@ These options have been set to their current values for some time and we do not
1127
1258
 
1128
1259
  #### Migration Steps
1129
1260
 
1130
- * `polyfillVueUseHead` is implementable in user-land with [this plugin](https://github.com/nuxt/nuxt/blob/f209158352b09d1986aa320e29ff36353b91c358/packages/nuxt/src/head/runtime/plugins/vueuse-head-polyfill.ts#L10-L11)
1261
+ - `polyfillVueUseHead` is implementable in user-land with [this plugin](https://github.com/nuxt/nuxt/blob/f209158352b09d1986aa320e29ff36353b91c358/packages/nuxt/src/head/runtime/plugins/vueuse-head-polyfill.ts#L10-L11)
1131
1262
 
1132
- * `respectNoSSRHeader`is implementable in user-land with [server middleware](https://github.com/nuxt/nuxt/blob/c660b39447f0d5b8790c0826092638d321cd6821/packages/nuxt/src/core/runtime/nitro/no-ssr.ts#L8-L9)
1263
+ - `respectNoSSRHeader`is implementable in user-land with [server middleware](https://github.com/nuxt/nuxt/blob/c660b39447f0d5b8790c0826092638d321cd6821/packages/nuxt/src/core/runtime/nitro/no-ssr.ts#L8-L9)
1133
1264
 
1134
1265
  ### Removal of Top-Level `generate` Configuration
1135
1266
 
@@ -1139,8 +1270,8 @@ These options have been set to their current values for some time and we do not
1139
1270
 
1140
1271
  The top-level `generate` configuration option is no longer available in Nuxt 4. This includes all of its properties:
1141
1272
 
1142
- * `generate.exclude` - for excluding routes from prerendering
1143
- * `generate.routes` - for specifying routes to prerender
1273
+ - `generate.exclude` - for excluding routes from prerendering
1274
+ - `generate.routes` - for specifying routes to prerender
1144
1275
 
1145
1276
  #### Reasons for Change
1146
1277
 
@@ -1195,7 +1326,7 @@ Static sites | ✅ | ✅ | ✅
1195
1326
 
1196
1327
  The migration guide provides a step-by-step comparison of Nuxt 2 features to Nuxt 3+ features and guidance to adapt your current application.
1197
1328
 
1198
- ::read-more{to="/docs/migration/overview"}
1329
+ ::read-more{to="/docs/4.x/migration/overview"}
1199
1330
  Check out the **guide to migrating from Nuxt 2 to Nuxt 3**.
1200
1331
  ::
1201
1332
 
@@ -1203,6 +1334,6 @@ Check out the **guide to migrating from Nuxt 2 to Nuxt 3**.
1203
1334
 
1204
1335
  If you prefer to progressively migrate your Nuxt 2 application to Nuxt 3, you can use Nuxt Bridge. Nuxt Bridge is a compatibility layer that allows you to use Nuxt 3+ features in Nuxt 2 with an opt-in mechanism.
1205
1336
 
1206
- ::read-more{to="/docs/bridge/overview"}
1337
+ ::read-more{to="/docs/4.x/bridge/overview"}
1207
1338
  **Migrate from Nuxt 2 to Nuxt Bridge**
1208
1339
  ::
@@ -7,19 +7,19 @@ surround: false
7
7
  ---
8
8
 
9
9
  ::card-group{class="sm:grid-cols-1"}
10
- ::card{icon="i-lucide-medal" title="Key Concepts" to="/docs/guide/concepts"}
11
- Discover the main concepts behind Nuxt, from auto-import, hybrid rendering to its TypeScript support.
12
- ::
13
- ::card{icon="i-lucide-folders" title="Directory Structure" to="/docs/guide/directory-structure"}
10
+ ::card{icon="i-lucide-folders" title="Directory Structure" to="/docs/4.x/guide/directory-structure"}
14
11
  Learn about Nuxt directory structure and what benefits each directory or file offers.
15
12
  ::
16
- ::card{icon="i-lucide-star" title="Going Further" to="/docs/guide/going-further"}
13
+ ::card{icon="i-lucide-medal" title="Key Concepts" to="/docs/4.x/guide/concepts"}
14
+ Discover the main concepts behind Nuxt, from auto-import, hybrid rendering to its TypeScript support.
15
+ ::
16
+ ::card{icon="i-lucide-star" title="Going Further" to="/docs/4.x/guide/going-further"}
17
17
  Master Nuxt with advanced concepts like experimental features, hooks, modules, and more.
18
18
  ::
19
- ::card{icon="i-lucide-book-open" title="Recipes" to="/docs/guide/recipes"}
19
+ ::card{icon="i-lucide-book-open" title="Recipes" to="/docs/4.x/guide/recipes"}
20
20
  Find solutions to common problems and learn how to implement them in your Nuxt project.
21
21
  ::
22
- ::card{icon="i-lucide-square-check" title="Best Practices" to="/docs/guide/best-practices"}
22
+ ::card{icon="i-lucide-square-check" title="Best Practices" to="/docs/4.x/guide/best-practices"}
23
23
  Learn about best practices when developing with Nuxt
24
24
  ::
25
25
  ::
@@ -1,3 +1,3 @@
1
1
  title: Directory Structure
2
2
  titleTemplate: '%s · Nuxt Directory Structure'
3
- icon: i-lucide-folders
3
+ icon: i-vscode-icons-default-folder