0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

create-react-app + TypeScript: 初っ端からnpm startでエラーが出たときの対処法

Posted at
バージョン情報
- TypeScript: 4.1.2
- create-react-app: 4.0.0

エラー内容

Reactアプリをサクッと書きたいときに便利なcreate-react-app
TypeScriptで書きたいなと思ったときには、

npx create-react-app [app name] --template typescript

と書くことで簡単に作成してくれるのですが、create-react-appのバージョンを4.0.0にした途端、npm startをしてみると

path\to\app\node_modules\react-scripts\scripts\utils\verifyTypeScriptSetup.js:239
      appTsConfig.compilerOptions[option] = value;
                                          ^

TypeError: Cannot assign to read only property 'jsx' of object '#<Object>'

のように怒られてしまう問題が発生しました。

解決方法

  1. create-react-appによって作成されたtsconfig.jsonを削除
  2. その状態でnpm startまたはyarn startする。(ここで自動的にtsconfig.jsonが再作成される)
  3. なぜか動くようになる!!!

何が違うのか気になったため2つのtsconfig.jsonを比較しましたが、何も違いませんでした
なぜ動くんだ......

(参考: https://github.com/facebook/create-react-app/issues/10117)

0
2
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?