This repository is a minimal repro for filing an issue to Vue Core, focusing on an inconsistency when a single SFC <script> contains multiple export default declarations: JavaScript throws, TypeScript does not.
- Related query:
https://github.com/vuejs/core/issues?q=script%20multiple%20export%20default%20error
- In plain JavaScript SFCs,
vue/compiler-sfcthrows a syntax error: only one default export is allowed per module. - In TypeScript SFCs (
<script lang="ts">),compileScriptreturns content that still contains twoexport defaultblocks without throwing, which differs from JS behavior.
src/ComponentVanilla.vue: JS variant with twoexport defaultdeclarationssrc/ComponentTS.vue: TS variant (<script lang="ts">) with twoexport defaultdeclarationscompile.ts: usesvue/compiler-sfcparse+compileScriptto compile and log resultscompileJavascriptCode.ts: runs compilation for the JS componentcompileTypescriptCode.ts: runs compilation for the TS component
- Node.js ≥ 18 (verified with v22)
- Package manager:
yarnornpm
yarn installornpm install
-
JS repro
- Command:
npx tsx compileJavascriptCode.ts - Expected: throws duplicate default export error
- Example:
Only one default export allowed per module.(DuplicateDefaultExport) - Also prints
target lang js
- Example:
- Command:
-
TS repro
- Command:
npx tsx compileTypescriptCode.ts - Expected: does not throw; prints the compiled content
- Logs
lang-> ts - Logs
content->followed by the twoexport defaultblocks
- Logs
- Command:
-
JS (
src/ComponentVanilla.vue):error SyntaxError: [vue/compiler-sfc] Only one default export allowed per module.reasonCode: 'DuplicateDefaultExport'target lang js
-
TS (
src/ComponentTS.vue):lang-> tscontent->shows twoexport default {...}blocks; no error
- Expected: TypeScript and JavaScript should be consistent and both report an error when multiple
export defaultare present in the same module. - Actual: JS errors; TS does not. The discrepancy warrants discussion and alignment in Vue Core.
- To keep things simple, this repro uses
npx tsxto run the TypeScript driver files directly; no additional build setup is required.