Environment
Stackblitz:
------------------------------
- Operating System: Linux
- Node Version: v18.20.3
- Nuxt Version: 3.15.4
- CLI Version: 3.21.1
- Nitro Version: 2.10.4
- Package Manager: npm@10.2.3
- Builder: -
- User Config: compatibilityDate, devtools, nitro
- Runtime Modules: -
- Build Modules: -
------------------------------
Reproduction
https://stackblitz.com/edit/github-mf8dpej3?file=app.vue
Important: Please use npm run build && npx serve .output/public to see the issue. You will not see the behaviour described below if you use npm run dev.
Describe the bug
It seems Nuxt's auto-import feature does not work correctly when building a static site with a component loaded inside a JSX render function. If I set nitro: { static: true } in nuxt.config.ts and run npm run build && npx serve .output/public on
<script setup lang="jsx">
const Jsx = <SomeComponent />;
</script>
<template>
<div>
<Jsx />
<SomeOtherComponent />
</div>
</template>
then the <Jsx /> is replaced with <somecomponent /> instead of the component body.
Manually importing SomeComponent (import SomeComponent from '~/components/SomeComponent.vue') fixes the issue. I'd be happy to add these imports, but then it would be great if npm run build warned me about missing imports instead of silently creating a broken build.
Adding <SomeOtherComponent /> to the example is necessary to reproduce the bug. The <Jsx /> resolves correctly if the <SomeOtherComponent /> line is removed.
Additional context
I've previously posted a slightly modified version of this issue on Discord. The Discord post was more a "can anyone tell me what's going on?" then a bug report, though, so I hope reposting here is okay.
Logs
Environment
Stackblitz:
Reproduction
https://stackblitz.com/edit/github-mf8dpej3?file=app.vue
Important: Please use
npm run build && npx serve .output/publicto see the issue. You will not see the behaviour described below if you usenpm run dev.Describe the bug
It seems Nuxt's auto-import feature does not work correctly when building a static site with a component loaded inside a JSX render function. If I set
nitro: { static: true }innuxt.config.tsand runnpm run build && npx serve .output/publiconthen the
<Jsx />is replaced with<somecomponent />instead of the component body.Manually importing
SomeComponent(import SomeComponent from '~/components/SomeComponent.vue') fixes the issue. I'd be happy to add these imports, but then it would be great ifnpm run buildwarned me about missing imports instead of silently creating a broken build.Adding
<SomeOtherComponent />to the example is necessary to reproduce the bug. The<Jsx />resolves correctly if the<SomeOtherComponent />line is removed.Additional context
I've previously posted a slightly modified version of this issue on Discord. The Discord post was more a "can anyone tell me what's going on?" then a bug report, though, so I hope reposting here is okay.
Logs