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
-
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], |
|
}, |
|
}) |
|
} |
-
compiler-sfc registers the file scope as global.
https://github.com/vuejs/core/blob/e9c676f/packages/compiler-sfc/src/script/resolveType.ts#L824-L834
-
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
-
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
Environment
Darwinv24.10.04.2.13.30.02.12.9pnpm@10.21.0-compatibilityDate--Reproduction
https://github.com/sinrabansyo/repro-nuxt-33694
Describe the bug
addTypeTemplateadds the file tovue.script.globalTypeFiles.nuxt/packages/kit/src/template.ts
Lines 101 to 108 in ce14d05
compiler-sfc registers the file scope as global.
https://github.com/vuejs/core/blob/e9c676f/packages/compiler-sfc/src/script/resolveType.ts#L824-L834
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
Types imported from added files cannot be used as input for
defineProps.Additional context
This issue requires compiler-sfc to run
resolveGlobalScopebefore resolving the props of components that import added files. If you remove the script block inapp.vue, you will find the error disappears.Workaround: use
addTemplatewithwrite: true.Logs