In trying to update the TypeScript React Starter, I'm trying to leverage the newly supported support in CRA; however, running create-react-app with the --typescript flag seems to not do anything, and the process of adding TypeScript in general has a bit of friction.
As an example, I ran
npx create-react-app myapp --typescript
I expected at least the following:
.ts/.tsx files.tsconfig.json file should have been given to me out of the box.typescript, @types/react, and @types/react-dom.Instead,
--typescript flag didn't do anything special, and I had to rename a file like App.js to App.tsx before yarn start gave me a tsconfig.json.yarn start told to run yarn add typescript after the rename (which is misleading since it should be a devDependency - so yarn add -D typescript).yarn start one more time, I was given a type-error because I was missing @types/react and @types/react-dom as devDependencies.Then everything worked, but this feels extremely frictiony. And it's also fairly confusing, because this flag doesn't seem to give anything beyond what the standard CRA scaffolding gives. And other issues have pointed this out too:
The issue is #5939 was that npx was using an old, cached version of Create React App. Perhaps the case for you too?
I'm guessing we should file a bug with npx or find an alternative way of creating apps, does "npm init react-app" behave differently?
npm init appears to use npx under the hood so I imagine the behaviour would be the same: https://docs.npmjs.com/cli/init#description
I agree though, this has happened a few times so it's probably worth mentioning it to npm.
@DanielRosenwasser I can confirm that I'm not hitting this issue on my machine either, I don't have a global install of create-react-app.
Could you confirm if you do?
Also, have you tried running yarn create react-app --typescript? Does that perform the same way?
I am running into the same issue right now trying to create my first typescript react app using npx create-react-app myapp --typescript. I have create-react-app installed globally.
If you're using npx, make sure you don't have create-react-app installed globally, as it will used the installed version i believe.
npm uninstall -g create-react-app
@ianschmitz You were right, I globally uninstalled create-react-app (and typescript just to be safe) and it worked this time around! Thanks for the help!
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.
This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue.
Most helpful comment
If you're using
npx, make sure you don't havecreate-react-appinstalled globally, as it will used the installed version i believe.npm uninstall -g create-react-app