Skip to content

Auto-import fails to import components used in JSX when building static site #30929

Description

@ettersi

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions