Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create-react-app with -–template typescript not creating .tsx files

I decided to use React JS with TypeScript. Doing a simple hello world project. Referring two books, and they both suggest the following. Brand new project, not upgrading or any of those scenarios. Starting fresh.

npx create-react-app try-react -–template typescript

That works fine.

But, the files, they still have the .js extension. In the book, one of them has a screenshot, it is already with .tsx extension.

I have looked at this link, https://create-react-app.dev/docs/adding-typescript/. It says,

If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app or yarn global remove create-react-app to ensure that npx always uses the latest version.

Global installs of create-react-app are no longer supported.

So, I removed the global install. tried again.

Same thing. no files with .tsx extension. The book author does not mention anything about having to rename these files manually.

So, my question is,

  1. is the template not supposed to automatically set all extensions to .tsx?
  2. is the only way to do this is to manually change from .js to .tsx?
  3. do we always do this, and that is indeed the norm. Perhaps, the book author did do it manually but forgot to include it in the instructions?
like image 463
Jay Avatar asked Dec 30 '20 10:12

Jay


Video Answer


1 Answers

I had the same problem. What solved it for me:

npm install cra-template-typescript

For some reason the template was not there for me.

like image 88
Alex Buyny Avatar answered Sep 25 '22 03:09

Alex Buyny