Create-react-app: Friction in TypeScript setup experience

Created on 3 Jan 2019  路  9Comments  路  Source: facebook/create-react-app

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:

  1. My files should have been .ts/.tsx files.
  2. A prescriptive tsconfig.json file should have been given to me out of the box.
  3. My devDependencies should have included typescript, @types/react, and @types/react-dom.

Instead,

  1. The --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.
  2. 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).
  3. Running 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:

stale

Most helpful comment

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

All 9 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adrice727 picture adrice727  路  3Comments

ap13p picture ap13p  路  3Comments

fson picture fson  路  3Comments

stopachka picture stopachka  路  3Comments

jnachtigall picture jnachtigall  路  3Comments