tk3118’s blog

技術ブログっぽいただのブログです。

【TypeScript】~ using the 'esModuleInterop' flag.と言われた時の対応

概要

以下のようなエラーが出るときがあります。

This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

対応としては、tsc のフラグに --esModuleInterop を付けるだけになります。 例としてはこんな感じ↓

# これを
$ tsc hoge.ts
# ↓ こうする
$ tsc hoge.ts --esModuleInterop

または, tsconfig.jsonの compilerOptionsに以下の記述をします。

"compilerOptions": {
    "esModuleInterop": true,
}

詳細

--esModuleInteropflagの説明に関しては、
こちらの記事が参考になるかと思います。 qiita.com