nuxt.config file.
Migrate to defineNuxtConfig
You should migrate to the newdefineNuxtConfig function that provides a typed configuration schema.
Router Configuration
Extending Routes
If you were usingrouter.extendRoutes, migrate to the new pages:extend hook:
Route Name Splitter
If you were usingrouter.routeNameSplitter, you can achieve the same result by updating route name generation logic in the new pages:extend hook:
ESM Syntax
Nuxt 3 is an ESM native framework. Althoughunjs/jiti provides semi compatibility when loading nuxt.config file, avoid any usage of require and module.exports in this file.
- Change
module.exportstoexport default - Change
const lib = require('lib')toimport lib from 'lib'
Async Configuration
Environment Variables
Nuxt has built-in support for loading.env files. Avoid directly importing it from nuxt.config.
Modules
Nuxt and Nuxt modules are now build-time-only.Migration Steps
- Move all your
buildModulesintomodules- There is no longer a distinction between build and runtime modules. - Check for Nuxt 3 compatibility of modules - Some modules may need updates.
- Update local module paths - If you have any local modules pointing to a directory, update this to point to the entry file:
Directory Changes
Thestatic/ directory (for storing static assets) has been renamed to public/. You can either rename your static directory to public, or keep the name by setting dir.public in your nuxt.config.
TypeScript
It will be much easier to migrate your application if you use Nuxt’s TypeScript integration. This does not mean you need to write your application in TypeScript, just that Nuxt will provide automatic type hints for your editor.Nuxt can type-check your app using
vue-tsc with nuxt typecheck command.Setup TypeScript
- Create a
tsconfig.jsonwith the following content:
- Run
npx nuxt prepareto generate the tsconfig files. - Install Volar following the instructions in the docs.
Vue Changes
There are a number of changes to what is recommended Vue best practice, as well as a number of breaking changes between Vue 2 and 3. It is recommended to read the Vue 3 migration guide and in particular the breaking changes list.Vuex
Nuxt no longer provides a Vuex integration. Instead, the official Vue recommendation is to usepinia, which has built-in Nuxt support via a Nuxt module.
Migrate to Pinia
A simple way to provide global state management with pinia:- Install the
@pinia/nuxtmodule:
- Enable the module in your nuxt configuration:
- Create a
storefolder at the root of your application:
store/index.ts
- Create a plugin file to globalize your store:
app/plugins/pinia.ts
Keep Using Vuex
If you want to keep using Vuex, you can manually migrate to Vuex 4 following these steps. Once it’s done, you will need to add the following plugin to your Nuxt app:app/plugins/vuex.ts