Uncaught SyntaxError: The requested module '/src/fuga/hoge

エラー内容

Uncaught SyntaxError: The requested module '/src/fuga/hoge/hogeCore.ts' does not provide an export named 'HogeType' (at Sketch.tsx:5:3)

解決方法

1. エラーフロー

  flowchart TD
    A[Sketch.tsx が HogeType をインポート] --> B{hogeCore.ts の export を確認}
    B --> C[export type HogeType は型のみ]
    C --> D[esbuild がコンパイル時に型を消去]
    D --> E[ブラウザ実行時: HogeType が存在しない]
    E --> F[SyntaxError: no export named HogeType]

2. 原因分析

export type は TypeScript の型情報のみで、コンパイル後の JS には残らない。Vite(esbuild)は isolatedModules モードで動作するため、型インポートを値インポートと区別できない通常の import { HogeType } は実行時エラーになる。

3. 解決策

Sketch.tsx の import を type キーワード付きに修正。