#defineNuxtPlugin - unable to type

4 messages · Page 1 of 1 (latest)

silk ivy
#

Hi I have a simple plugin (from shadcn-vue docs). Hoewever I am unable to type this as Plugin does not seem to be defined for void type?

import { provideSSRWidth } from '@vueuse/core'

export default defineNuxtPlugin((nuxtApp) => {
  provideSSRWidth(1024, nuxtApp.vueApp)
})
jagged dragonBOT
#

Hi @silk ivy. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

The knowledge sources don’t mention this exact typing issue with defineNuxtPlugin, so I can’t give a fully authoritative, source-backed fix. The closest related info is general defineNuxtPlugin usage and plugin typing, but not this specific void/Plugin problem.[defineNuxtPlugin docs]

In Nuxt 3, a plugin passed to defineNuxtPlugin can either:

  • return nothing (i.e. void), or
  • return an object with provide, etc.

Your example:

import { provideSSRWidth } from '@vueuse/core'

export default defineNuxtPlugin((nuxtApp) => {
  provideSSRWidth(1024, nuxtApp.vueApp)
})

is valid as a side‑effect plugin: it calls provideSSRWidth and doesn’t need to return anything. The inferred return type of the callback is void, which is acceptable for defineNuxtPlugin according to the docs.[defineNuxtPlugin docs]

If your IDE is complaining about the return type, the sources don’t show a documented workaround beyond:

  • keeping it as-is (side-effect plugin, no return), or
  • changing it to an explicit void return if your tooling insists:
export default defineNuxtPlugin((nuxtApp): void => {
  provideSSRWidth(1024, nuxtApp.vueApp)
})

If the error persists, it’s likely an editor/TypeScript tooling quirk rather than a Nuxt typing rule; the provided docs don’t go deeper into that.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@silk ivy Kapa.ai is still learning and improving, please let me know how I did by reacting below.