TypeScript support has been externalized in dedicated packages and have been removed from core starting Nuxt 2.9. Here are the guidelines to migrate your existing Nuxt TypeScript project to 2.9 without any trouble.
The following migration guide works for either nuxt
or nuxt-edge
.
yarn remove @nuxt/typescript
yarn add -D @nuxt/typescript-build @nuxt/types
Use
npm uninstall
andnpm install -D
instead if you're using npm
// tsconfig.json
"compilerOptions": {
"types": [
"@nuxt/types"
]
}
If you were importing types from @nuxt/config
you need to instead import them from @nuxt/types
. Types imports might have changed a little, you can get familiar with them either by triggering intellisense when importing or watch them live here now.
// nuxt.config.js
export default {
modules: ['@nuxt/typescript-build']
}
// nuxt.config.js
export default {
typescript: {
typeCheck: true,
ignoreNotFoundWarnings: true
}
}
You can also do it this way :
// nuxt.config.js
export default {
modules: [
['@nuxt/typescript-build', {
typeCheck: true,
ignoreNotFoundWarnings: true
}]
]
}
Install @nuxt/typescript-runtime
and use nuxt-ts
(or nuxts
alias) command instead of nuxt
/nuxt-edge
to have TypeScript runtime and be able to use TypeScript in files executed at runtime such as configuration (nuxt.config.ts
), modules
and serverMiddlewares
.
yarn add @nuxt/typescript-runtime
// package.json
"scripts": {
"dev": "nuxt-ts",
"build": "nuxt-ts build",
"start": "nuxt-ts start"
"generate": "nuxt-ts generate"
}