LoginSignup
9
4

More than 3 years have passed since last update.

react nativeでtypescriptを使ってproject初めたかったのに、typescriptが適用されなかった問題

Last updated at Posted at 2020-07-04

問題

react nativeで何かアプリを作ろうとして、その際にtypescriptで始めようとしたのです。その際に公式のドキュメント通りに、以下を叩きました。

npx react-native init <MyApp> --template react-native-template-typescript

しかしあらびっくり。。作成されたディレクトリを覗いてみると、普通のJSプロジェクトになっていました。という事象です。

エラー文を見てみると、こんな感じ。

(node:20898) UnhandledPromiseRejectionWarning: Error: Command failed: npm install --save --save-exact react-native-template-react-native-template-typescript

解決策

https://github.com/react-native-community/react-native-template-typescript/issues/80
上記によれば、インストールしているreact-native-cliが悪さをしているみたい。react-native-cliをインストールする際にnpm install -g react-native-cliでインストールをすると、問題が起きるようです。。
たしかに、react-native-cliをインストールする時にこのコマンドを使った覚えがありました。

ではどうすればよいのかというと、下記の流れでうまくいきました。

npm uninstall -g react-native-cli // 既存のcliを削除

npm i -g @react-native-community/cli // こっちのcliをインストール

npx react-native init <MyApp> --template react-native-template-typescript
9
4
2

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
9
4