Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue <script setup> not working #4319

Closed
1 task
DerYeger opened this issue Aug 14, 2022 · 6 comments · Fixed by #4706
Closed
1 task

Vue <script setup> not working #4319

DerYeger opened this issue Aug 14, 2022 · 6 comments · Fixed by #4706
Assignees
Labels
- P5: urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority) pkg: vue Related to Vue (scope)

Comments

@DerYeger
Copy link
Contributor

DerYeger commented Aug 14, 2022

What version of astro are you using?

1.0.5

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

yarn

What operating system are you using?

Mac

Describe the Bug

Importing a Vue component "B" in a Vue component "A" breaks the build, if the import happens in a <script setup> block as seen below. This should be working as described here.

<script setup lang="ts">
import B from './B.vue'
</script>

The following method works, but is cumbersome.

<script lang="ts">
import { defineComponent } from 'vue'
import B from './B.vue'

export default defineComponent({
  components: {
    B,
  },
})
</script>

Link to Minimal Reproducible Example

https://github.com/DerYeger/astro-vue-import-reproduction

Participation

  • I am willing to submit a pull request for this issue.
@darusk
Copy link

darusk commented Aug 14, 2022

This also might be some form of clash in the way Vue and/or [p]react components are rendered. If preact and react are removed from the astro.config.mjs file, the example seems to build ok.

If either react or preact integrations are enabled, and the Vue component uses the <script setup> composition API you get the following error during build which was what was originally shown on the support thread:

 generating static routes 
▶ src/pages/index.astro
 error   Unable to render A!

  This component likely uses @astrojs/react, @astrojs/preact, @astrojs/vue or @astrojs/svelte,
  but Astro encountered an error during server-side rendering.

  Please ensure that A:
  1. Does not unconditionally access browser-specific globals like `window` or `document`.
     If this is unavoidable, use the `client:only` hydration directive.
  2. Does not conditionally return `null` or `undefined` when rendered on the server.

  If you're still stuck, please open an issue on GitHub or join us at https://astro.build/chat.

It however runs fine on the dev server

@bluwy bluwy added the pkg: vue Related to Vue (scope) label Aug 15, 2022
@natemoo-re
Copy link
Member

Thanks for digging in, @bluwy! I'll take a look at this.

@natemoo-re natemoo-re added the - P5: urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority) label Aug 15, 2022
@natemoo-re natemoo-re self-assigned this Aug 15, 2022
@Satont
Copy link

Satont commented Aug 16, 2022

Same here, by the way.

@darusk
Copy link

darusk commented Aug 24, 2022

Was looking at this a little more. If you render component 'A' with the client:only="vue" directive it seems to build ok. However the components are literally only templates, so I imagine Vue must hit one of the conditions the error mentions when using the composition API.

@diegoleme
Copy link
Contributor

diegoleme commented Sep 1, 2022

Same here. Version 1.1.3

@alexbruno
Copy link

alexbruno commented Sep 8, 2022

It works for me!
I'm using just Astro + Vue in 3 projects. Every Vue component is using script setup and everything is working and building ok.
So I guess this happens only if you have other front-end integrations running in the same project like @darusk already suggested.
Astro and Vue versions: latest, ever!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P5: urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority) pkg: vue Related to Vue (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants