#Unable to resolve default imports in template

5 messages · Page 1 of 1 (latest)

worthy steeple
#

Since this morning default-imports can not me resolved by typescript when using them in the template.

Example:

// test.ts
export const namedExport = true;

export default 'default export working';
<template>
<div>
  <!-- All good -->
  {{ namedExport }} 

  <!-- Typescript error `Property 'defaultExport' does not exist on type '...'` -->
  {{ defaultExport }} 
</div>
</template>

<script lang="ts" setup>
import { namedExport } from "./utils/test";
import defaultExport from "./utils/test";
</script>

Reproduction:

olive rainBOT
#

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

#

The knowledge sources don’t mention this specific issue with default imports in <script setup> not being recognized in the template type context, so I can’t confirm an official fix or workaround from Nuxt.

From what is available:

  • There are recent changes around auto‑imports and shared type contexts (e.g. nuxt.shared.d.ts, types/shared.d.ts) that were made to fix missing type definitions for auto‑imports in the shared/ directory, but these deal with Nuxt’s auto‑import system, not with explicit import foo from './x' in SFCs.[shared auto-imports]
  • Other linked issues and PRs in the provided context are about path aliases, test files, template import resolution, or HMR, and none describe or fix the exact “default import not visible in template” problem you’re seeing.[template imports]

Because of that, I don’t have a Nuxt‑documented solution to point you to. Based on the sources:

  • This looks like a regression or limitation in the current type generation / Volar integration rather than intended behavior, but the knowledge sources don’t show an issue or PR tracking it.
  • There’s no documented config flag or hook in the provided material that would specifically fix default imports in templates.

Given the constraints of the knowledge I have, the only concrete suggestion I can make (grounded in the sources) is:

  • Ensure you’re on the latest Nuxt version, since several type‑related regressions have been fixed recently (e.g. around shared imports and tsconfig/typecheck mismatches).[shared auto-imports]
  • If the problem persists, it likely needs to be reported (or may already be tracked) as a new issue, since nothing in the provided issues/PRs matches your reproduction.
#

I’m sorry I can’t give a more direct fix; the current knowledge sources simply don’t contain one for this specific default‑import template type error.

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

#

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