Getting error from Nuxt when using #imports in a plugin template
Environment
- Operating System: Darwin
- Node Version: v18.18.0
- Nuxt Version: 3.8.2
- CLI Version: 3.10.0
- Nitro Version: 2.8.1
- Package Manager: [email protected]
- Builder: -
- User Config: modules, myModule, devtools
- Runtime Modules: ../src/module
- Build Modules: -
Reproduction
https://github.com/MooseSaeed/my-module/blob/master/src/module.ts
Describe the bug
The addPluginTemplate() in @nuxt/kit throws the below error to the console when importing defineNuxtPlugin from #imports:
[nuxt] `#imports` should be transformed with real imports. There seems to be something wrong with the imports plugin.
The error goes away if I import defineNuxtPlugin from #app instead of #imports even though the documentation's example is using #imports
Also the error doesn't occur with npx nuxi build. It only shows up by running dev.
Additional context
Didn't raise the issue on module-builder or Module Starter Template because the issue is happening when using local modules too.
Logs
TEST Plugin Template - build time 7:37:13 PM
ℹ Vite client warmed up in 372ms 7:37:14 PM
ℹ Vite server warmed up in 546ms 7:37:14 PM
✔ Nitro built in 248 ms nitro 7:37:14 PM
[nuxt] `#imports` should be transformed with real imports. There seems to be something wrong with the imports plugin.
TEST Plugin Template
Getting the same earning using Vuefire and @posva suggests it could be a Nuxt issue as well.
This is because you've named your file .ejs and Nuxt doesn't know anything about that file extension (so it doesn't process it). Instead, you can add a valid extension, e.g.:
addPluginTemplate({
src: resolve("./runtime/templates/template-plugin.ejs"),
+ filename: 'template-plugin.mjs',
options: {
ssr: true,
},
});
I’m not using ejs but still have the same issue with Vuefire
@3zzy can you provide a reproduction?