Skip to content

addTypeTemplate prevents the exported types of added files from being resolved by compiler-sfc #33694

@KazariEX

Description

@KazariEX

Environment

  • Operating System: Darwin
  • Node Version: v24.10.0
  • Nuxt Version: 4.2.1
  • CLI Version: 3.30.0
  • Nitro Version: 2.12.9
  • Package Manager: pnpm@10.21.0
  • Builder: -
  • User Config: compatibilityDate
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://github.com/sinrabansyo/repro-nuxt-33694

Describe the bug

  1. addTypeTemplate adds the file to vue.script.globalTypeFiles.

    if (!context || context.nuxt || context.shared) {
    // expose global types to vue compiler
    nuxt.options.vite.vue = defu(nuxt.options.vite.vue, {
    script: {
    globalTypeFiles: [template.dst],
    },
    })
    }

  2. compiler-sfc registers the file scope as global.
    https://github.com/vuejs/core/blob/e9c676f/packages/compiler-sfc/src/script/resolveType.ts#L824-L834

  3. compiler-sfc only resolves exported types that are not in the global file scope.
    https://github.com/vuejs/core/blob/e9c676f/packages/compiler-sfc/src/script/resolveType.ts#L1316-L1370

  4. Types imported from added files cannot be used as input for defineProps.

    import type { Foo } from "#build/foo";
    
    defineProps<Foo>(); /* [@vue/compiler-sfc] Unresolvable type reference or unsupported built-in utility type */

Additional context

This issue requires compiler-sfc to run resolveGlobalScope before resolving the props of components that import added files. If you remove the script block in app.vue, you will find the error disappears.

Workaround: use addTemplate with write: true.

Logs

Metadata

Metadata

Assignees

Labels

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions