Runtime (optional)

Nuxt 2.15 and above comes with runtime TypeScript support built-in so usage of this package is no longer needed nor recommended in those versions.

TypeScript runtime is needed for files not compiled by Webpack, such as nuxt.config file, local modules and serverMiddlewares.

Nuxt.js has created a TypeScript runtime wrapper under a dedicated package @nuxt/typescript-runtime. The wrapper is a binary named nuxt-ts that registers ts-node behind the scenes before running.

Installation

yarn add @nuxt/typescript-runtime
npm install @nuxt/typescript-runtime

Note that this package is installed as dependency and not devDependency like @nuxt/typescript-build, cause @nuxt/typescript-runtime is needed for production.

Usage

All you need to do is update your package.json file:

"scripts": {
  "dev": "nuxt",
  "build": "nuxt build",
  "generate": "nuxt generate",
  "start": "nuxt start"
},
"dependencies": {
  "@nuxt/typescript-runtime": "latest",
  "nuxt": "2.x"
},
"devDependencies": {
  "@nuxt/types": "2.x",
  "@nuxt/typescript-build": "latest"
}

You can now use TypeScript for nuxt.config file, local modules and serverMiddlewares.

@nuxt/typescript-runtime does not support programmatic usage (as it extends @nuxt/cli).

Advanced users might try adding the following code to your server entrypoint (see source):

import { register } from 'ts-node'

register({
  project: 'tsconfig.json',
  compilerOptions: {
    module: 'commonjs'
  },
  transpileOnly: true
})

However, this is not recommended or supported.