TypeScriptのエラーについてです。
次のようにnpmパッケージをインストールし、tsファイル で import したところ、以下のエラーが出て困りました。
$ npm install xxx
hoge.ts
import xxx from "xxx";
エラーについて
Module 'xxx' can only be default-imported 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.
直し方
エラーメッセージをきちんと読むとわかるのですが、 tsconfig.json の compilerOptions
に "esModuleInterop": true
を追加してあげます。
これで、import xxx from "xxx"
を使うことができます。
tsconfig.json
{
"compilerOptions": {
"esModuleInterop": true
}
}