未経験からのReact入門『TypeScript』|環境構築

準備

npm にバンドルされている npx を使用するため、node.js をインストールしてください。

環境作成

npx コマンドで React アプリケーションを作成します。

テンプレートオプションに typescript を追加してください。

npx create-react-app my-app --template typescript

cd my-app
npm run start

通常はこれで起動できますが、環境によっては以下エラーが表示される可能性があります。

There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.

The react-scripts package provided by Create React App requires a dependency:

"babel-loader": "8.1.0"

Don't try to install it manually: your package manager does it automatically.
However, a different version of babel-loader was detected higher up in the tree:

その場合、プロジェクトディレクトリに以下の.env ファイルを配置してください。

vi .env
SKIP_PREFLIGHT_CHECK = true