LoginSignup
7
5

More than 3 years have passed since last update.

error : Module 'xxx' can only be default-imported using the 'esModuleInterop' flag

Posted at

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
  }
}
7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5