question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create React App does not work with Typescript template

See original GitHub issue

Describe the bug

On a fresh project setup via yarn and create-react-app, when I specific the typescript template, The project fails to build.

Did you try recovering your dependencies?

I have updated to the latest stable version of Yarn 1 (1.22.4) and latest version of create-react-app (create-react-app@3.4.1)

Which terms did you search for in User Guide?

Searched any references to typescript and the error as it presents itself.

Environment

Occurs both on Mac OS Catalina and WSL

Steps to reproduce

  1. yarn create react-app project --template typescript
  2. cd project
  3. yarn run build

error also present on yarn start

Expected behavior

Build success.

Actual behavior

yarn run build
yarn run v1.22.4
$ react-scripts build
Creating an optimized production build...
Failed to compile.

/home/matwrz/project/node_modules/@types/testing-library__react/node_modules/pretty-format/build/index.d.ts
TypeScript error in /home/matwrz/project/node_modules/@types/testing-library__react/node_modules/pretty-format/build/index.d.ts(7,13):
'=' expected.  TS1005

     5 |  * LICENSE file in the root directory of this source tree.
     6 |  */
  >  7 | import type * as PrettyFormat from './types';
       |             ^
     8 | /**
     9 |  * Returns a presentation string of your `val` object
    10 |  * @param val any potential JavaScript object


error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Reproducible demo

Project that CRA generates from yarn create react-app project --template typescript https://github.com/MatWrz/cra-project-issue

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:7

github_iconTop GitHub Comments

5reactions
hleboncommented, Mar 25, 2020

I updated typescript to 3.8.3 and works. maybe some Issues related to the compiler?

2reactions
ghostcommented, Mar 25, 2020

Looks like it’s caused by version 25.2.0 of pretty-format used by @types/testing-library__react. As a temporary fix you can manually install 25.1.0, remove node_modules and package-lock.json and it’ll work:

npx create-react-app my-project --template typescript
cd my-project && npm install pretty-format@25.1.0 --save-exact
rm -r node_modules package-lock.json
npm install && npm start
Read more comments on GitHub >

github_iconTop Results From Across the Web

create-react-app --template typescript doesn't work
According to the CRA's TS guide, the command needs react-scripts@2.1.0 or higher. · But the version listed in my-app 's package.json is only...
Read more >
Adding TypeScript - Create React App
Installation​. To start a new Create React App project with TypeScript, you can run: npx create-react-app my-app --template typescript
Read more >
create react app --typescript does not work (it create ... - GitHub
Describe the bug recently, I use create react app to create a typescript app, but it create a js app with no typescript...
Read more >
Create React App and TypeScript: A Quick How-To | Built In
You can start a new TypeScript app using templates. To use our provided TypeScript template, append --template typescript to the creation ...
Read more >
How to Use Create React App With TypeScript
The Create React App will be launched using the TypeScript template as shown in the image below. On the left sidebar, we have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found