mattpocock / ts-error-translator

VSCode extension to turn TypeScript errors into plain English
https://ts-error-translator.vercel.app
2.36k stars 90 forks source link

Translation request for 2306 #222

Open minierparedes opened 11 months ago

minierparedes commented 11 months ago

Error Text

"File '...TodoButton.vue.ts' is not a module.ts(2306)"

Supporting Information

Issue: Vue SFC Import Error: "File '...TodoButton.vue.ts' is not a module.ts(2306)"

Description: When trying to import a Vue Single File Component (SFC) in a TypeScript environment, the error message "File '...TodoButton.vue.ts' is not a module.ts(2306)" is encountered.

Steps to Reproduce:

  1. Create a Vue SFC (e.g., TodoButton.vue).
  2. Within the SFC, use a <script> tag with lang="ts" but without the setup attribute.
  3. In another component or Vue file, try to import the aforementioned SFC.

Expected Behavior: The Vue SFC should be imported without any errors.

Actual Behavior: The error "File '...TodoButton.vue.ts' is not a module.ts(2306)" is thrown, making it seem as though the imported Vue component is not recognized as a proper module.

Solution: Ensure that the <script> tag in the Vue SFC includes the setup attribute when working in the Composition API context with TypeScript:

<script setup lang="ts">
  // Your setup code here
</script>

By adding the setup attribute, Vue treats the file as a proper module/component, and the error is resolved.

Environment: