N
Nuxt2y ago
Gary

defineNuxtPlugin is not defined

Why would a module I write that uses "addPlugin" cause this issue?
defineNuxtPlugin is not defined
defineNuxtPlugin is not defined
It works fine in the development mode in the playground but bombs when I implement it as a package.
8 Replies
Gary
GaryOP2y ago
It appears that you have to do something like:
import { defineNuxtPlugin, useRuntimeConfig } from '#imports'
import { defineNuxtPlugin, useRuntimeConfig } from '#imports'
in the plugin sort of like this: https://github.com/nuxt/image/blob/main/src/runtime/plugin.ts
GitHub
image/plugin.ts at main · nuxt/image
Plug-and-play image optimization for Nuxt applications. - image/plugin.ts at main · nuxt/image
Gary
GaryOP2y ago
Also, it's the same with something like ref - why do I have to import all the things when it's a module?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Gary
GaryOP2y ago
Thanks so much @unai - You were totally right on. I found the note in the docs after posting here - not sure how I missed that. Thanks again for clearing that up. I am now getting a really odd error on the application implementing my code: ERROR: Could not resolve "#imports" It gripes about this in three composables. I've tripled checked and I don't think they are being used outside of a setup function. Thanks @fuyu ! any insight on the application not being able to resolve "#imports"?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Gary
GaryOP2y ago
AutoImports has been disabled But in a few places where I'm doing something like import { useCookie } from '#imports' I'm getting ERROR: Could not resolve "#imports" Just want to confirm @fuyu - if auto-imports are disabled I do have to import them from #imports, correct?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Gary
GaryOP2y ago
Gotcha - yeah, it seems that the module starter kit automatically disables autoimport b/c it's inefficent to have it on for things that are in the node_modules directory (cause thats where it ends up) and that makes sense to me. This error... man... no sense For future knowledge I ended up addressing this by placing this in the final project's nuxt config:
vite: {
optimizeDeps: {
exclude: [
'#imports',
],
},
}
vite: {
optimizeDeps: {
exclude: [
'#imports',
],
},
}
Want results from more Discord servers?
Add your server