From Nuxt 2 to Nuxt 3: a rebuild, not an update
Moving an application from Nuxt 2 to Nuxt 3 changes more than a version number: Vue 2 becomes Vue 3, webpack 4 and Babel become Vite by default, the server becomes Nitro, and Vuex is no longer built in. In this article I describe what changes according to the official documentation, where the typical pitfalls are and in which order I approach such a migration: library first, then the move. It is based on a web application for a testing and inspection company that I moved with the team in two stages, in 2024 and 2025.
Why is this a rebuild and not an update?
Nuxt 3 stands on different foundations. The Nuxt migration overview names three major shifts: from Vue 2 to Vue 3 with the Composition API and <script setup> as the default, from webpack 4 and Babel to Vite or webpack 5 with esbuild, and from Nuxt as a runtime dependency to a minimal, standalone server compiled by Nitro. In my experience each of these shifts touches a large part of the code on its own. Together they mean that hardly a file stays the same.
The pressure comes from both sides. Vue 2 reached its end of life on 31 December 2023 and has not received any updates since, including security and browser compatibility fixes. Nuxt 2 has been unsupported since 30 June 2024.
A note on where things stand today: Nuxt 4 was released on 15 July 2025. If you start from Nuxt 2 today, check Nuxt 4 as your target. The big break, however, lies between Nuxt 2 and Nuxt 3, and that break is what this article is about.
What changes in configuration and build?
nuxt.config becomes an ES module using defineNuxtConfig, which comes with a typed schema. module.exports becomes export default, buildModules merges into modules, and the static/ folder is now public/. Nuxt loads a .env file itself, so importing dotenv in the configuration is no longer needed.
On the build side the documentation is clear: most of the previous build configuration in nuxt.config is ignored, including any custom Babel configuration. Its place is taken by the vite, webpack and postcss keys. The default is Vite through @nuxt/vite-builder. Webpack loaders and plugins from the old project therefore have to be checked one by one and replaced with their Vite counterpart where needed.
One place that is easy to overlook is runtime configuration. publicRuntimeConfig and privateRuntimeConfig merge into a single runtimeConfig. Its values are overridden at runtime by matching environment variables, and if you want to read environment variables in the application, this is the way to do it in Nuxt 3:
export default defineNuxtConfig({
runtimeConfig: {
apiSecret: '123',
public: {
apiBase: '/api',
},
},
})
The matching environment variables are NUXT_API_SECRET and NUXT_PUBLIC_API_BASE. In the browser only the keys under public are available, on the server the whole configuration. Secrets therefore never belong under public.
How do asyncData and fetch become the new data fetching?
The asyncData and fetch hooks no longer exist in this form. The documentation recommends replacing both with useAsyncData or useFetch. useAsyncData replaces both hooks and can do more than simply fetch data from an endpoint. useFetch is a convenience wrapper around it for the most common case, fetching from an endpoint:
const route = useRoute()
const { data: post, refresh } = await useFetch(`/api/posts/${route.params.id}`)
There is a lot of work here, because in Nuxt 2 data fetching, loading state and error handling are often spread across component, store and plugin. I use the rebuild to pull this logic together into composables. Then each data source has one place that pages and components share.
What happens to plugins, middleware, head and pages?
Plugins get a new format with exactly one argument, nuxtApp. inject becomes nuxtApp.provide, and access then goes through nuxtApp.$name. Files directly in the plugins/ folder and index files in its subfolders are registered automatically, and instead of the mode option the environment is part of the file name, for example .client.ts.
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.provide('injected', () => 'my injected function')
})
Route middleware is written with defineNuxtRouteMiddleware and redirects with navigateTo. Nuxt recognises global middleware by its file name, for example auth.global.ts. If you access component state in the head, you switch to useHead.
Pages and layouts use different building blocks: app.vue becomes the central entry point, layouts use a <slot />, nested routes render through <NuxtPage>, and dynamic parameters are called [id] instead of _id. These are many small changes that work well as a checklist, and each of them has to be applied page by page.
Which Vue 3 changes affect your own code?
The more demanding part is often Vue itself. From the official migration guide, these are the breaking changes I run into most often in practice:
- Filters are removed. The guide recommends replacing them with computed properties or methods.
$on,$offand$onceare removed. A global event bus has to move to an external library such as mitt or tiny-emitter, or better, be replaced with props, events and shared state.v-modelon components works withmodelValueand theupdate:modelValueevent instead ofvalueandinput. The.syncmodifier is gone, and in return severalv-modelbindings on one component are possible.$listenersno longer exists, event listeners are now part of$attrs.- Instead of
new Vue,createAppcreates an app instance. Global registrations are therefore attached to the app, no longer to the Vue constructor.
Vue offers a migration build for the transition, @vue/compat, which runs Vue 3 with Vue 2 compatible behaviour. The Nuxt documentation, however, states that it currently cannot be used with Nuxt 3. In a Nuxt project this intermediate step does not exist. Dependencies are just as critical: libraries that rely on internal Vue 2 APIs need a Vue 3 version or a replacement. I make this list before the first change, because it often sets the schedule.
Why the component library first?
Components are where most Vue 2 specifics accumulate: v-model on custom inputs, forwarded $listeners, filters in templates. That is why I recommend rebuilding them first, isolated from the pages: library first, then the move. In the project for the testing and inspection company a modular component library in Storybook was built, together with reusable composables.
This has two benefits. Each component can be checked on its own in Storybook, with all its states and without the whole application running yet. And when the pages move afterwards, they assemble finished, tested building blocks instead of repairing old and new logic at the same time. Accessibility according to WCAG can be built in at this point too, because keyboard operation, focus and labels are created in the component and not again on every page.
I secured the rebuild with unit and snapshot tests in Vitest. For Nuxt there is @nuxt/test-utils with its own nuxt test environment, a Nuxt runtime environment for code that relies on Nuxt composables, auto-imports or the Nuxt context. mountSuspended mounts a component in this environment, with async setup and access to the injections of the Nuxt plugins, and a snapshot records the result:
const component = await mountSuspended(SomeComponent)
expect(component.text()).toMatchInlineSnapshot(
'"This is an auto-imported component"',
)
Snapshot tests do not replace functional tests. In a migration they are still valuable, because they make every unintended change in the output visible.
Where does the Vuex store go?
Nuxt 3 no longer ships a Vuex integration. The documentation points to Pinia, which Vue recommends, registered through the @pinia/nuxt module. If you want to keep Vuex, you have to move to Vuex 4 yourself and register it with a plugin. In the project Pinia handles state management.
Pinia has two kinds of stores, defined with an options object or with a setup function. In a setup store, values created with ref() become state, values created with computed() become getters and functions become actions:
export const useCounterStore = defineStore('counter', () => {
const count = ref(0)
const doubleCount = computed(() => count.value * 2)
function increment() {
count.value++
}
return { count, doubleCount, increment }
})
A Vuex module can usually be turned into a store one to one. Mutations no longer exist: they become actions that change the state directly, or components write to the store directly. This makes the code shorter, but it means finding the places where components relied on mutations so far.
What I take away from the migration
- Be honest about the scope: Vue 3, a new bundler, Nitro and a new store are four rebuilds at once.
- Check dependencies first. Whatever has no Vue 3 version sets the schedule.
- Library first, then the move: rebuild and test the components in isolation in Storybook, then the pages.
- Bundle data fetching in composables instead of translating
asyncDatafile by file. - Write tests before the rebuild, not after. Snapshots reveal differences that get lost when clicking through.
- Build accessibility into the new components right away instead of retrofitting it later.