Compatibility
Nuxt Kit provides a set of utilities to help you check the compatibility of your modules with different Nuxt versions. Nuxt Kit utilities can be used in Nuxt 3, Nuxt 2 with Bridge and even Nuxt 2 without Bridge. To make sure your module is compatible with all versions, you can use the compatibility functions.checkNuxtCompatibility
Checks if constraints are met for the current Nuxt version. If not, returns an array of messages. Nuxt 2 version also checks for bridge support.
Type
Parameters
constraints: Version and builder constraints to check against.
| Property | Type | Required | Description |
|---|---|---|---|
nuxt | string | false | Nuxt version in semver format. Versions may be defined in Node.js way, for example: >=2.15.0 <3.0.0. |
bridge | Record<string, string | false> | false | Specifies version constraints or disables compatibility for specific Nuxt builders like vite, webpack, or rspack. Use false to disable. |
nuxt: Nuxt instance. If not provided, it will be retrieved from the context via useNuxt() call.
Usage
assertNuxtCompatibility
Asserts that constraints are met for the current Nuxt version. If not, throws an error with the list of issues as string.
Type
Parameters
constraints: Version and builder constraints to check against. Same as checkNuxtCompatibility.
nuxt: Nuxt instance. If not provided, it will be retrieved from the context via useNuxt() call.
Usage
hasNuxtCompatibility
Checks if constraints are met for the current Nuxt version. Return true if all constraints are met, otherwise returns false. Nuxt 2 version also checks for bridge support.
Type
Parameters
constraints: Version and builder constraints to check against. Same as checkNuxtCompatibility.
nuxt: Nuxt instance. If not provided, it will be retrieved from the context via useNuxt() call.
Usage
isNuxtMajorVersion
Check if current Nuxt instance is of specified major version.
Type
Parameters
major: Major version to check against.
nuxt: Nuxt instance. If not provided, it will be retrieved from the context via useNuxt() call.
Usage
isNuxt3
Checks if the current Nuxt version is 3.x.
Note: Use isNuxtMajorVersion(3, nuxt) instead. This may be removed in @nuxt/kit v5 or a future major version.
Type
Parameters
nuxt: Nuxt instance. If not provided, it will be retrieved from the context via useNuxt() call.
isNuxt2
Checks if the current Nuxt version is 2.x.
Note: Use isNuxtMajorVersion(2, nuxt) instead. This may be removed in @nuxt/kit v5 or a future major version.
Type
Parameters
nuxt: Nuxt instance. If not provided, it will be retrieved from the context via useNuxt() call.
getNuxtVersion
Returns the current Nuxt version.
Type
Parameters
nuxt: Nuxt instance. If not provided, it will be retrieved from the context via useNuxt() call.