Skip to content

Fi2zz/vue-compiler-ts-multi-export-default

Repository files navigation

Repro: Multiple export default in <script> — JS throws, TS does not

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

Problem Statement

  • In plain JavaScript SFCs, vue/compiler-sfc throws a syntax error: only one default export is allowed per module.
  • In TypeScript SFCs (<script lang="ts">), compileScript returns content that still contains two export default blocks without throwing, which differs from JS behavior.

Repository Layout

  • src/ComponentVanilla.vue: JS variant with two export default declarations
  • src/ComponentTS.vue: TS variant (<script lang="ts">) with two export default declarations
  • compile.ts: uses vue/compiler-sfc parse + compileScript to compile and log results
  • compileJavascriptCode.ts: runs compilation for the JS component
  • compileTypescriptCode.ts: runs compilation for the TS component

Requirements

  • Node.js ≥ 18 (verified with v22)
  • Package manager: yarn or npm

Install

  • yarn install or
  • npm install

Reproduce

  1. 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
  2. TS repro

    • Command: npx tsx compileTypescriptCode.ts
    • Expected: does not throw; prints the compiled content
      • Logs lang-> ts
      • Logs content-> followed by the two export default blocks

Sample Output

  • 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-> ts
    • content-> shows two export default {...} blocks; no error

Expected vs Actual

  • Expected: TypeScript and JavaScript should be consistent and both report an error when multiple export default are present in the same module.
  • Actual: JS errors; TS does not. The discrepancy warrants discussion and alignment in Vue Core.

Notes

  • To keep things simple, this repro uses npx tsx to run the TypeScript driver files directly; no additional build setup is required.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •