2023-06-20 18:17:07 +00:00
---
title: "Experimental Features"
2023-10-18 10:59:43 +00:00
description: "Enable Nuxt experimental features to unlock new possibilities."
2023-06-20 18:17:07 +00:00
---
The Nuxt experimental features can be enabled in the Nuxt configuration file.
2023-10-18 10:59:43 +00:00
Internally, Nuxt uses `@nuxt/schema` to define these experimental features. You can refer to the [API documentation ](/docs/api/configuration/nuxt-config#experimental ) or the [source code ](https://github.com/nuxt/nuxt/blob/main/packages/schema/src/config/experimental.ts ) for more information.
2024-02-21 17:09:45 +00:00
::note
2023-06-20 18:17:07 +00:00
Note that these features are experimental and could be removed or modified in the future.
::
2023-09-19 20:24:02 +00:00
## asyncContext
2023-10-18 10:59:43 +00:00
Enable native async context to be accessible for nested composables in Nuxt and in Nitro. This opens the possibility to use composables inside async composables and reduce the chance to get the `Nuxt instance is unavailable` error.
2023-09-19 20:24:02 +00:00
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-13 14:35:48 +00:00
export default defineNuxtConfig({
2023-10-18 10:59:43 +00:00
experimental: {
asyncContext: true
}
})
2023-09-19 20:24:02 +00:00
```
2023-10-18 10:59:43 +00:00
::read-more{icon="i-simple-icons-github" color="gray" to="https://github.com/nuxt/nuxt/pull/20918" target="_blank"}
See full explanation on the GitHub pull-request.
::
2023-06-20 18:17:07 +00:00
## asyncEntry
Enables generation of an async entry point for the Vue bundle, aiding module federation support.
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-13 14:35:48 +00:00
export default defineNuxtConfig({
2023-10-18 10:59:43 +00:00
experimental: {
asyncEntry: true
}
})
2023-06-20 18:17:07 +00:00
```
## externalVue
Externalizes `vue` , `@vue/*` and `vue-router` when building.
2023-10-18 10:59:43 +00:00
2023-06-20 18:17:07 +00:00
*Enabled by default.*
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-13 14:35:48 +00:00
export default defineNuxtConfig({
2023-10-18 10:59:43 +00:00
experimental: {
externalVue: true
}
})
2023-06-20 18:17:07 +00:00
```
2024-02-21 17:09:45 +00:00
::warning
2023-10-18 10:59:43 +00:00
This feature will likely be removed in a near future.
2023-06-20 18:17:07 +00:00
::
## treeshakeClientOnly
Tree shakes contents of client-only components from server bundle.
2023-10-18 10:59:43 +00:00
2023-06-20 18:17:07 +00:00
*Enabled by default.*
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-13 14:35:48 +00:00
export default defineNuxtConfig({
2023-10-18 10:59:43 +00:00
experimental: {
treeshakeClientOnly: true
}
})
2023-06-20 18:17:07 +00:00
```
## emitRouteChunkError
Emits `app:chunkError` hook when there is an error loading vite/webpack chunks. Default behavior is to perform a hard reload of the new route when a chunk fails to load.
2023-10-18 10:59:43 +00:00
2023-06-20 18:17:07 +00:00
You can disable automatic handling by setting this to `false` , or handle chunk errors manually by setting it to `manual` .
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-13 14:35:48 +00:00
export default defineNuxtConfig({
2023-10-18 10:59:43 +00:00
experimental: {
emitRouteChunkError: 'automatic' // or 'manual' or false
}
})
2023-06-20 18:17:07 +00:00
```
## restoreState
2023-10-18 10:59:43 +00:00
Allows Nuxt app state to be restored from `sessionStorage` when reloading the page after a chunk error or manual [`reloadNuxtApp()` ](/docs/api/utils/reload-nuxt-app ) call.
2023-06-20 18:17:07 +00:00
2023-10-18 10:59:43 +00:00
To avoid hydration errors, it will be applied only after the Vue app has been mounted, meaning there may be a flicker on initial load.
2024-02-21 17:09:45 +00:00
::important
2023-06-20 18:17:07 +00:00
Consider carefully before enabling this as it can cause unexpected behavior,
2023-07-07 16:24:09 +00:00
and consider providing explicit keys to [`useState` ](/docs/api/composables/use-state ) as auto-generated keys may not match across builds.
2023-06-20 18:17:07 +00:00
::
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-13 14:35:48 +00:00
export default defineNuxtConfig({
2023-10-18 10:59:43 +00:00
experimental: {
restoreState: true
}
})
2023-06-20 18:17:07 +00:00
```
2023-10-18 10:59:43 +00:00
## inlineRouteRules
Define route rules at the page level using [`defineRouteRules` ](/docs/api/utils/define-route-rules ).
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-13 14:35:48 +00:00
export default defineNuxtConfig({
2023-10-18 10:59:43 +00:00
experimental: {
inlineRouteRules: true
}
})
```
Matching route rules will be created, based on the page's `path` .
::read-more{to="/docs/api/utils/define-route-rules" icon="i-ph-function-duotone"}
Read more in `defineRouteRules` utility.
::
:read-more{to="/docs/guide/concepts/rendering#hybrid-rendering" icon="i-ph-medal-duotone"}
2023-06-20 18:17:07 +00:00
## renderJsonPayloads
Allows rendering of JSON payloads with support for revivifying complex types.
2023-10-18 10:59:43 +00:00
2023-06-20 18:17:07 +00:00
*Enabled by default.*
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-13 14:35:48 +00:00
export default defineNuxtConfig({
2023-10-18 10:59:43 +00:00
experimental: {
renderJsonPayloads: true
}
})
2023-06-20 18:17:07 +00:00
```
## noVueServer
Disables Vue server renderer endpoint within Nitro.
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-13 14:35:48 +00:00
export default defineNuxtConfig({
2023-10-18 10:59:43 +00:00
experimental: {
noVueServer: true
}
})
2023-06-20 18:17:07 +00:00
```
## payloadExtraction
Enables extraction of payloads of pages generated with `nuxt generate` .
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-13 14:35:48 +00:00
export default defineNuxtConfig({
2023-10-18 10:59:43 +00:00
experimental: {
payloadExtraction: true
}
})
2023-06-20 18:17:07 +00:00
```
## clientFallback
2023-10-18 10:59:43 +00:00
Enables the experimental [`<NuxtClientFallback>` ](/docs/api/components/nuxt-client-fallback ) component for rendering content on the client if there's an error in SSR.
2023-06-20 18:17:07 +00:00
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-13 14:35:48 +00:00
export default defineNuxtConfig({
2023-10-18 10:59:43 +00:00
experimental: {
clientFallback: true
}
})
2023-06-20 18:17:07 +00:00
```
## crossOriginPrefetch
Enables cross-origin prefetch using the Speculation Rules API.
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-13 14:35:48 +00:00
export default defineNuxtConfig({
2023-10-18 10:59:43 +00:00
experimental: {
crossOriginPrefetch: true
}
})
2023-06-20 18:17:07 +00:00
```
2023-10-18 10:59:43 +00:00
::read-more{icon="i-simple-icons-w3c" color="gray" to="https://wicg.github.io/nav-speculation/prefetch.html" target="_blank"}
Read more about the **Speculation Rules API** .
::
2023-06-20 18:17:07 +00:00
## viewTransition
Enables View Transition API integration with client-side router.
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-13 14:35:48 +00:00
export default defineNuxtConfig({
2023-10-18 10:59:43 +00:00
experimental: {
viewTransition: true
}
})
2023-06-20 18:17:07 +00:00
```
2023-10-18 10:59:43 +00:00
:link-example{to="https://stackblitz.com/edit/nuxt-view-transitions?file=app.vue" target="_blank"}
::read-more{icon="i-simple-icons-mdnwebdocs" color="gray" to="https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API" target="_blank"}
Read more about the **View Transition API** .
2023-08-08 15:11:32 +00:00
::
2023-06-20 18:17:07 +00:00
## writeEarlyHints
Enables writing of early hints when using node server.
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-13 14:35:48 +00:00
export default defineNuxtConfig({
2023-10-18 10:59:43 +00:00
experimental: {
writeEarlyHints: true
}
})
2023-06-20 18:17:07 +00:00
```
## componentIslands
2023-10-18 10:59:43 +00:00
Enables experimental component islands support with [`<NuxtIsland>` ](/docs/api/components/nuxt-island ) and `.island.vue` files.
2023-06-20 18:17:07 +00:00
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-13 14:35:48 +00:00
export default defineNuxtConfig({
2023-10-18 10:59:43 +00:00
experimental: {
componentIslands: true // false or 'local+remote'
}
})
2023-06-20 18:17:07 +00:00
```
2023-10-18 10:59:43 +00:00
:read-more{to="/docs/guide/directory-structure/components#server-components"}
2023-06-20 18:17:07 +00:00
2023-10-18 10:59:43 +00:00
::read-more{icon="i-simple-icons-github" color="gray" to="https://github.com/nuxt/nuxt/issues/19772" target="_blank"}
You can follow the server components roadmap on GitHub.
::
2023-06-20 18:17:07 +00:00
## configSchema
Enables config schema support.
2023-10-18 10:59:43 +00:00
2023-06-20 18:17:07 +00:00
*Enabled by default.*
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-13 14:35:48 +00:00
export default defineNuxtConfig({
2023-10-18 10:59:43 +00:00
experimental: {
configSchema: true
}
})
2023-06-20 18:17:07 +00:00
```
## polyfillVueUseHead
Adds a compatibility layer for modules, plugins, or user code relying on the old `@vueuse/head` API.
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-13 14:35:48 +00:00
export default defineNuxtConfig({
2023-10-18 10:59:43 +00:00
experimental: {
polyfillVueUseHead: false
}
})
2023-06-20 18:17:07 +00:00
```
## respectNoSSRHeader
Allow disabling Nuxt SSR responses by setting the `x-nuxt-no-ssr` header.
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-13 14:35:48 +00:00
export default defineNuxtConfig({
2023-10-18 10:59:43 +00:00
experimental: {
respectNoSSRHeader: false
}
})
2023-06-20 18:17:07 +00:00
```
## localLayerAliases
Resolve `~` , `~~` , `@` and `@@` aliases located within layers with respect to their layer source and root directories.
2023-10-18 10:59:43 +00:00
2023-06-20 18:17:07 +00:00
*Enabled by default.*
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-13 14:35:48 +00:00
export default defineNuxtConfig({
2023-10-18 10:59:43 +00:00
experimental: {
localLayerAliases: true
}
})
2023-06-20 18:17:07 +00:00
```
## typedPages
2023-10-18 10:59:43 +00:00
Enable the new experimental typed router using [`unplugin-vue-router` ](https://github.com/posva/unplugin-vue-router ).
2023-06-20 18:17:07 +00:00
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-13 14:35:48 +00:00
export default defineNuxtConfig({
2023-10-18 10:59:43 +00:00
experimental: {
2023-11-23 20:48:06 +00:00
typedPages: true
2023-10-18 10:59:43 +00:00
}
})
2023-06-20 18:17:07 +00:00
```
2023-10-18 10:59:43 +00:00
Out of the box, this will enable typed usage of [`navigateTo` ](/docs/api/utils/navigate-to ), [`<NuxtLink>` ](/docs/api/components/nuxt-link ), [`router.push()` ](/docs/api/composables/use-router ) and more.
2023-06-20 18:17:07 +00:00
You can even get typed params within a page by using `const route = useRoute('route-name')` .
2024-05-13 14:39:52 +00:00
::tip{icon="i-ph-video-duotone" to="https://www.youtube.com/watch?v=SXk-L19gTZk" target="_blank"}
Watch a video from Daniel Roe explaining type-safe routing in Nuxt.
::
2023-06-20 18:17:07 +00:00
## watcher
Set an alternative watcher that will be used as the watching service for Nuxt.
2023-10-18 10:59:43 +00:00
2023-06-20 18:17:07 +00:00
Nuxt uses `chokidar-granular` by default, which will ignore top-level directories
(like `node_modules` and `.git` ) that are excluded from watching.
2023-10-18 10:59:43 +00:00
2023-06-20 18:17:07 +00:00
You can set this instead to `parcel` to use `@parcel/watcher` , which may improve
performance in large projects or on Windows platforms.
2023-10-18 10:59:43 +00:00
2023-06-20 18:17:07 +00:00
You can also set this to `chokidar` to watch all files in your source directory.
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-21 17:09:45 +00:00
export default defineNuxtConfig({
experimental: {
2024-01-18 10:01:39 +00:00
watcher: 'chokidar-granular' // 'chokidar' or 'parcel' are also options
2024-02-21 17:09:45 +00:00
}
})
2023-06-20 18:17:07 +00:00
```
2024-01-18 10:01:39 +00:00
## sharedPrerenderData
Enabling this feature automatically shares payload *data* between pages that are prerendered. This can result
in a significant performance improvement when prerendering sites that use `useAsyncData` or `useFetch` and
fetch the same data in different pages.
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-21 17:09:45 +00:00
export default defineNuxtConfig({
experimental: {
2024-01-18 10:01:39 +00:00
sharedPrerenderData: true
2024-02-21 17:09:45 +00:00
}
})
2024-01-18 10:01:39 +00:00
```
2024-05-13 14:39:52 +00:00
::tip{icon="i-ph-video-duotone" to="https://www.youtube.com/watch?v=1jUupYHVvrU" target="_blank"}
Watch a video from Alexander Lichter about the experimental `sharedPrerenderData` setting.
::
2024-01-18 10:01:39 +00:00
It is particularly important when enabling this feature to make sure that any unique key of your data
is always resolvable to the same data. For example, if you are using `useAsyncData` to fetch
data related to a particular page, you should provide a key that uniquely matches that data. (`useFetch`
should do this automatically for you.)
```ts
// This would be unsafe in a dynamic page (e.g. `[slug].vue` ) because the route slug makes a difference
// to the data fetched, but Nuxt can't know that because it's not reflected in the key.
const route = useRoute()
const { data } = await useAsyncData(async () => {
return await $fetch(`/api/my-page/${route.params.slug}`)
})
// Instead, you should use a key that uniquely identifies the data fetched.
const { data } = await useAsyncData(route.params.slug, async () => {
return await $fetch(`/api/my-page/${route.params.slug}`)
})
2024-01-18 16:09:27 +00:00
```
## clientNodeCompat
With this feature, Nuxt will automatically polyfill Node.js imports in the client build using [`unenv` ](https://github.com/unjs/unenv ).
::alert{type=info}
To make globals like `Buffer` work in the browser, you need to manually inject them.
```ts
import { Buffer } from 'node:buffer'
globalThis.Buffer = globalThis.Buffer || Buffer
```
::
2024-01-29 10:37:32 +00:00
2024-01-29 16:44:54 +00:00
## scanPageMeta
This option allows exposing some route metadata defined in `definePageMeta` at build-time to modules (specifically `alias` , `name` , `path` , `redirect` ).
This only works with static or strings/arrays rather than variables or conditional assignment. See [original issue ](https://github.com/nuxt/nuxt/issues/24770 ) for more information and context.
2024-06-10 16:24:43 +00:00
You can disable this feature if it causes issues in your project.
2024-05-13 17:45:21 +00:00
```ts twoslash [nuxt.config.ts]
export default defineNuxtConfig({
experimental: {
scanPageMeta: false
}
})
2024-06-10 16:24:43 +00:00
```
2024-05-13 17:45:21 +00:00
2024-01-29 10:37:32 +00:00
## cookieStore
Enables CookieStore support to listen for cookie updates (if supported by the browser) and refresh `useCookie` ref values.
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2024-02-21 17:09:45 +00:00
export default defineNuxtConfig({
experimental: {
2024-01-29 10:37:32 +00:00
cookieStore: true
2024-02-21 17:09:45 +00:00
}
})
2024-01-29 10:37:32 +00:00
```
::read-more{icon="i-simple-icons-mdnwebdocs" color="gray" to="https://developer.mozilla.org/en-US/docs/Web/API/CookieStore" target="_blank"}
Read more about the **CookieStore** .
::