Vue | Module has no default export
Asked Answered
N

4

16

I'm facing an error with vue3, ts, vue cli where it says Module '"c:/Users/USER/Documents/top-secret-project/src/components/Features/Features.vue"' has no default export. when importing a component from a file I have no idea why did this specific component decide to now work.

here's Features.vue

<script lang="ts">
import Feature from "./Feature.vue";
</script>

<template>
  <Feature />
</template>
Neap answered 27/8, 2022 at 16:49 Comment(4)
Please share the content of Features.vue?Wellnigh
@BoussadjraBrahim, it's just a div with script setup and inside it is an import of a componentNeap
so where is said setup in your code?Histoid
Oh, well I didn't notice it ;-;Neap
W
10

With script setup syntax there's no need to add export default in your script, just add the setup attribute to your script:

<script lang="ts" setup>
import Feature from "./Feature.vue";
</script>

<template>
  <Feature />
</template>

You should disable Vetur extension and use Vue - official (ex Volar)

Wellnigh answered 27/8, 2022 at 18:17 Comment(4)
I'm using Vue 3 with vite and I'm thinking something is wrong with Vetur, because my code has setup as you said and it keep saying no export default in moduleArica
@Shad, you should disable vetur extension and use Volar instead of itWellnigh
Volar extension is deprecated. Use the Vue - Official (Id: Vue.volar)Steviestevy
@Steviestevy you're rightWellnigh
C
29

A @Boussadjra mentioned this could happen in Visual Studio Code if Vetur extension is installed there. Insetted of Vetur if we install Volar extension in Visual Studio Code this problem gets solved.

Convexoconvex answered 16/3, 2023 at 10:40 Comment(2)
This issue is addressed in the vue 3 documentation, vuejs.org/guide/typescript/overview.html#volar-takeover-mode.Nereidanereids
Adding to this answer, they have now marked Volar as deprecated and recommend to use Vue - Official extension instead (marketplace.visualstudio.com/items?itemName=Vue.volar)Hanford
W
10

With script setup syntax there's no need to add export default in your script, just add the setup attribute to your script:

<script lang="ts" setup>
import Feature from "./Feature.vue";
</script>

<template>
  <Feature />
</template>

You should disable Vetur extension and use Vue - official (ex Volar)

Wellnigh answered 27/8, 2022 at 18:17 Comment(4)
I'm using Vue 3 with vite and I'm thinking something is wrong with Vetur, because my code has setup as you said and it keep saying no export default in moduleArica
@Shad, you should disable vetur extension and use Volar instead of itWellnigh
Volar extension is deprecated. Use the Vue - Official (Id: Vue.volar)Steviestevy
@Steviestevy you're rightWellnigh
U
2

You must add export default in your component's script by example:

<script>
export default {
  name: "HelpView",
};
</script>
Uralian answered 27/8, 2022 at 17:13 Comment(0)
A
2

Official Recommended Setup

Just disable Vetur Ext and install Vue - Official Ext

Adellaadelle answered 6/6 at 12:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.