#[@vue/compiler-sfc] Failed to resolve extends base type.

1 messages · Page 1 of 1 (latest)

broken anchorBOT
#

Hi @zealous hill. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

This error is related to TypeScript type resolution in Vue Single File Components (SFCs) within your Nuxt project. The error occurs when the Vue compiler fails to resolve an extended interface or type in your component.

Understanding the Error

The error message indicates that the Vue compiler is having trouble resolving an extended type in the Switch.vue component from the @nuxt/ui package. This is a known issue that can occur with Vue 3.4+ and TypeScript.

How to Fix It

There are a few approaches to resolve this issue:

1. Add the lang="ts" attribute

Make sure your Vue components have the lang="ts" attribute in the script tag:

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

As seen in a Stack Overflow post, forgetting to add this attribute can cause TypeScript-related errors in Vue SFCs Stack Overflow Post.

2. Run nuxt prepare command

This error might be related to missing TypeScript definitions. Running nuxt prepare can generate the necessary TypeScript definitions for your project:

npx nuxt prepare

This is particularly important when working with layers that have their own tsconfig.json files, as mentioned in a GitHub issue Github Issue.

3. Use the Vue-ignore comment (as suggested in the error)

For immediate workarounds, you can use the /* @vue-ignore */ comment before the extends clause as suggested in the error message:

interface Props extends /* @vue-ignore */ Base {}

Note that this is just a workaround and not a permanent solution.

4. Check for version compatibility

This could be related to version compatibility issues between Vue and its compiler. Make sure your dependencies are compatible, especially if you're using Vue 3.4+.

#

If you're still experiencing issues, you might want to check your project's configuration, particularly the tsconfig.json file, to ensure it's properly set up for Vue and TypeScript integration in a Nuxt project.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@zealous hill Kapa.ai is still learning and improving, please let me know how I did by reacting below.

zealous hill
#

@broken anchor How to add interface Props extends /* @vue-ignore */ Base {} where?

broken anchorBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Based on the error message you received, you need to add the /* @vue-ignore */ comment in the component where you're extending a base type that the Vue compiler can't resolve.

In your specific case, the error is occurring in the @nuxt/ui package's Switch.vue component, which is in your node_modules folder. Since this is a third-party component, you can't directly modify it.

Instead, you have a few options:

Option 1: Update your dependencies

This issue might be related to version compatibility between TypeScript and the Vue compiler. You could try updating your TypeScript-related dependencies:

npm install -D @typescript-eslint/eslint-plugin @typescript-eslint/parser --legacy-peer-deps

As mentioned in this Stack Overflow post, using --legacy-peer-deps can help resolve conflicts by installing packages at the top of the dependency tree.

Option 2: Create your own component

If you need to use the Switch component but are encountering this error, you could create your own wrapper component that imports the UI component but handles the type extensions differently.

Option 3: Check your TypeScript configuration

Make sure your tsconfig.json is properly set up to extend the Nuxt-generated configuration:

{
  "extends": "./.nuxt/tsconfig.json",
  "compilerOptions": {
    // Your custom options here
  }
}

As noted in the Nuxt TypeScript documentation, overwriting options like "compilerOptions.paths" can lead to module resolution issues.

Option 4: Run nuxt prepare

Before running your application or tests, make sure to run:

npx nuxi prepare
#

This generates the necessary TypeScript definition files that might be missing, as mentioned in Nuxt's documentation.

The /* @vue-ignore */ comment is meant to be used in your own code when you're extending a type that the Vue compiler can't resolve, not as a fix for third-party components. If you were writing your own component with an interface that extends another type, you would add it like this:

<script setup lang="ts">
interface Props extends /* @vue-ignore */ BaseProps {
  // Your additional props here
}

const props = defineProps<Props>()
</script>

However, since the error is in a third-party component, the above direct modification approach won't work.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: