LoginSignup
55
16

More than 3 years have passed since last update.

React×Redux×Typescriptにおける環境開発で、初っ端からこけた際の対処法

Posted at

新しくReactをTypescriptで起動し、Reduxを導入しようとするとビルドできなくなるというエラーに突然ぶち当たりました。
とても簡単に解決できたので、備忘録として残しておきます。

いつも通り下記でReactアプリケーションをTypescriptで構築します。

npx create-react-app sample-ts-react-app --typescript

# この時点ではちゃんとビルドする
cd yarn
yarn build

ここで下記の手順で、reduxを導入すると突然エラーが出るようになりました。


npm install --save redux react-redux
npm install -D @types/react-redux
yarn build

#エラー文
TypeScript error in /sample-ts-react-app/src/App.tsx(1,19):
Could not find a declaration file for module 'react'. '/sample-ts-react-app/node_modules/react/index.js' implicitly has an 'any' type.
  If the 'react' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react`  TS7016

ドキュメントなどを読んで調べてみると、原因はtsconfigにあるようでした。
したがって下記をcreate-reaxct-appで生成されたtsconfig.jsonに追加するだけで、ちゃんと起動することができるようになりました。

    "noImplicitAny": false,

参考記事

55
16
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
55
16