この回答はGPT-4による自動生成回答です
tsconfig.jsonファイルをプロジェクトのルートディレクトリに作成し、以下のように設定してください。
json
1{
2 "compilerOptions": {
3 "module": "ES2020",
4 "target": "ES2020",
5 "moduleResolution": "node",
6 "esModuleInterop": true,
7 "outDir": "dist",
8 "baseUrl": ".",
9 "paths": {
10 "*": [
11 "node_modules/*",
12 "src/types/*"
13 ]
14 },
15 "allowSyntheticDefaultImports": true,
16 "sourceMap": true,
17 "strict": true,
18 "forceConsistentCasingInFileNames": true,
19 "resolveJsonModule": true,
20 "isolatedModules": true,
21 "noEmitOnError": true,
22 "importsNotUsedAsValues": "error",
23 "lib": [
24 "DOM",
25 "DOM.Iterable",
26 "ES2020"
27 ]
28 },
29 "include": [
30 "src/**/*.ts"
31 ],
32 "exclude": [
33 "node_modules",
34 "**/*.spec.ts"
35 ]
36}
この設定により、TypeScriptコンパイラは、import { Game } from './game';をimport { Game } from './game.js';に変換して出力します。これにより、ブラウザが正しくモジュールを読み込むことができます。