Migrating from Nuxt 3 to Nuxt 4: A Practical Guide
Nuxt 4 introduces a new project structure that moves source files into an app/ directory, bringing Nuxt closer to standard Vue/Nitro conventions.
The New Directory Structure
``
app/
assets/
components/
composables/
layouts/
middleware/
pages/
plugins/
stores/
app.vue
`
Key Changes
- app/ directory β All source code now lives under app/
. The rootpages/,components/, etc. directories are no longer auto-imported. - compatibilityVersion: 4 β Opt-in to Nuxt 4 behavior explicitly.
- Improved TypeScript β Better type inference for composables and auto-imports.
Migration Steps
Start by setting compatibilityVersion: 4 in your nuxt.config.ts:
`ts
export default defineNuxtConfig({
future: { compatibilityVersion: 4 },
})
`
Then move your source files into the app/ directory and update any path references.
Watch Out For
- Auto-imports: Components in app/components/
are still auto-imported, but nested paths may need explicitcomponents.dirsconfiguration. - Middleware: Global middleware must be in app/middleware/
with a.global.ts` suffix. - Plugins: Explicit plugin registration is now the recommended pattern.
Tags
More in Development
Adding Blazing-Fast Client-Side Search with Fuse.js
Implement fuzzy search for your blog using Fuse.js β zero server requirements, instant results, and a great developer experience.
State Management with Pinia in Nuxt 4
Setting up Pinia stores in Nuxt 4 with the manual plugin pattern β no module needed, just clean composition.