Nuxt Kit

Nuxt Kit provides composable utilities to make interacting with Nuxt Hooks and Nuxt Builder Core and developing Nuxt Modules super easy!

Usage

Install dependency

You can install the latest nuxt kit by adding it to the dependencies section of your package.json. However, please consider always explicitly installing the @nuxt/kit package even if it is already installed by nuxt.

package.json

  1. {
  2. "dependencies": {
  3. "@nuxt/kit": "npm:@nuxt/[email protected]"
  4. }
  5. }

Import kit utilities

test.mjs

  1. import { useNuxt } from '@nuxt/kit'

👉

Read more in API > Advanced > Kit.

Nuxt kit utilities are only available for modules and not meant to be imported in runtime (components, vue composables, pages, plugins, or server routes)

Nuxt kit, is an esm-only package meaning you cannot require('@nuxt/kit'). As a workaround, we can use dynamic import to use it in the CommonJS context:

test.cjs

  1. // This does NOT work!
  2. // const kit = require('@nuxt/kit')
  3. async function main() {
  4. const kit = await import('@nuxt/kit')
  5. }
  6. main()