LoginSignup
32
13

More than 5 years have passed since last update.

TypeScriptでimport React from 'react'って書きたい!

Last updated at Posted at 2019-02-18

書いてみる

import React from 'react';

すると以下のエラー出る。。。

Module '"~~~~/node_modules/@types/react/index"' has no default export.

~~~~は各々のファイルの場所です。)

以下にすればエラーが出なくなる。

import * as React from 'react';

そういうことじゃない!!

tsconfigを直す

allowSyntheticDefaultImports: true

これを足せばいいだけ!

https://www.typescriptlang.org/docs/handbook/compiler-options.html
上記からallowSyntheticDefaultImportsの説明を引用すると、、、

Allow default imports from modules with no default export. This does not affect code emit, just typechecking.

英語がわからないのでGoogle翻訳にぶん投げます。

デフォルトのエクスポートなしでモジュールからのデフォルトのインポートを許可します。これはコードの発行には影響せず、単に型チェックを行います。

has no default exportに対して解決してそうですね!

めでたし!

32
13
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
32
13