Create-react-app: Poor documentation of what it means to use --typescript option

Created on 1 Dec 2018  路  10Comments  路  Source: facebook/create-react-app

I was excited to see the new --typescript option. Used it to create a project, but there was no evidence that typescript support was added. Then I discovered a documentation page suggesting I should rename .js to .tsx and restart the server. Did that, but got the following error. Not clear why this is happening if I already created a project with --typescript option. The whole point of using create-react-app (for a newbie react developer) is to get started without messing with any configuration, but adding typescript support doesn't look straightforward.

Appreciate any help with clear instructions on what --typescript actually does. If it isn't creating the scaffolding for typescript, should I follow instructions to add typescript support to an existing create-react-app?

`We detected TypeScript in your project (src/App.tsx) and created a tsconfig.json file for you.

It looks like you're trying to use TypeScript but do not have typescript installed.
Please install typescript by running npm install typescript.
If you are not trying to use TypeScript, please remove the tsconfig.json file from your package root (and any TypeScript files).`

All 10 comments

There's an open PR that adds better documentation for the --typescript flag: https://github.com/facebook/create-react-app/pull/5866

"create a project, but there was no evidence that typescript support was added"

Have you updated your Create React App CLI tool?

This is required for it to scaffold with TypeScript files.

Timer, I think you are asking if I created a new create-react-app. I created a new one using "npx create-react-app --typescript". Just upgraded to latest npx on windows and have the same problem I reported last night. That first report was based on an install on a Mac (with a recently updated npm/npx).

If you meant something else, please elaborate what I should do to "update my Create React App CLI tool". I started with a new project.

npx will sometimes use a cached, old version. Can you run npx create-react-app --version and post the output?

Also, make sure you run npx create-react-app my-app --typescript and NOT npx create-react-app --typescript my-app.

npx create-react-app --version
1.5.1

This is a fresh install of npx, so no cache was involved. Yes, I made sure --typescript was at the end.

Ok, I see the latest version is 2.1.1, but somehow I got 1.5.1. I'll read up on how to banish cached older versions and report back.

I force flushed my npm cache on the windows box, but npx continued to report version 1.5.1. So I tried this on my Ubuntu box and it got version 2.1.1 and use of "--typescript" indeed installed typescript and setup .tsx files instead of .js.

Now I have to go back to the Mac where I first ran into this problem and figure out why it got stuck with an older version of create-react-app.

Maybe try npm init react-app my-app --typescript?

I found that I had an older version installed via Yarn, installed globally. Uninstalling it fixed my issues with NPX.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gaearon picture gaearon  路  152Comments

gabrielmicko picture gabrielmicko  路  70Comments

gaearon picture gaearon  路  85Comments

amuehl picture amuehl  路  79Comments

benneq picture benneq  路  99Comments