Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8705

error TS1192: Module '"fs"' has no default export.

$
0
0

モジュール '"fs"' に既定エクスポートがありません
error TS1192: Module '"fs"' has no default export.

のようなエラーが出た時の対処法メモ

結論

tsconfig.json"allowSyntheticDefaultImports": trueを追記する

{"compilerOptions":{"allowSyntheticDefaultImports":true}}

または

// error TS1192: Module '"fs"' has no default export.importfsfrom'fs'// no errorimport*asfsfrom'fs'

解説(tsconfigのオプション追加は省略)

TypeScriptでES6のデフォルト構文を使うとエラーでコンパイルエラーが起きます。

そういう時は下記の様な構文で指定ファイルの全てをインポートしてあげましょう。

import*asfsfrom'fs'

エラーが出ないもの

また、下記の様に個別にexportされたものをimportする場合はエラーが出ません。

// hogeModuleファイルexportconsthoge=()=>{}
import{hoge}from'hogeModule'

上記と同様にexport defaultが指定されているものもエラーになりません。

// hogeModuleexportdefaultclasshoge{}
importhogefrom'hogeModule'

記事のもと

https://github.com/microsoft/TypeScript/issues/3337
https://qiita.com/bouzuya/items/edf5274241b50f32c621
https://qiita.com/alfas/items/539ade65926deb530e0e


Viewing all articles
Browse latest Browse all 8705

Trending Articles