実現したいこと
【Uncaught SyntaxError: Unexpected token 'export'】を解決したいです。
発生している問題・分からないこと
【事象】
TSからJSにコンパイルした後、JSファイルに自動的にexportが記述されており、それが原因でエラーになってしまう。
【試行したこと】
JSのexportをコメントアウトすると、一時的にブラウザ上で正常に動作した。
→再度コンパイルすると、JSファイルが新規内容で上書きされるため、export文も追加されエラーになる。
exportが自動的に付与される理由についてご存知の方、ご教示頂きたく思います。
宜しくお願いします。
エラーメッセージ
error
1タイトルの通りです。
該当のソースコード
index.ts
1function responseFunc(value: string | number) { 2 if(typeof value === "string") { 3 console.log(`名前:${value}`); 4 } else if(typeof value === "number") { 5 console.log(`年齢:${value}歳`); 6 } 7} 8 9responseFunc("satoshi");
index.js
1function responseFunc(value) { 2 if (typeof value === "string") { 3 console.log(`名前:${value}`); 4 } 5 else if (typeof value === "number") { 6 console.log(`年齢:${value}歳`); 7 } 8} 9responseFunc("satoshi"); 10export {}; ←ここでエラーになる 11//# sourceMappingURL=index.js.map
tsconfig.json
1{ 2 // Visit https://aka.ms/tsconfig to read more about this file 3 "compilerOptions": { 4 // File Layout 5 // "rootDir": "./src", 6 "outDir": "./dist", 7 8 // Environment Settings 9 // See also https://aka.ms/tsconfig/module 10 "module": "esnext", 11 "target": "es2020", 12 "types": [], 13 // For nodejs: 14 // "lib": ["esnext"], 15 // "types": ["node"], 16 // and npm install -D @types/node 17 18 // Other Outputs 19 "sourceMap": true, 20 "declaration": true, 21 "declarationMap": true, 22 23 // Stricter Typechecking Options 24 "noUncheckedIndexedAccess": true, 25 "exactOptionalPropertyTypes": true, 26 27 // Style Options 28 // "noImplicitReturns": true, 29 // "noImplicitOverride": true, 30 // "noUnusedLocals": true, 31 // "noUnusedParameters": true, 32 // "noFallthroughCasesInSwitch": true, 33 // "noPropertyAccessFromIndexSignature": true, 34 35 // Recommended Options 36 "strict": true, 37 "jsx": "react-jsx", 38 "verbatimModuleSyntax": true, 39 "isolatedModules": true, 40 "noUncheckedSideEffectImports": true, 41 "moduleDetection": "force", 42 "skipLibCheck": true, 43 "moduleResolution": "node" 44 }, 45 "include": ["./src/**/*.ts"] 46} 47
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
根本原因の解決には至らなかった。
補足
特になし
回答1件
あなたの回答
tips
プレビュー