Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create-react-app error: import type * as PrettyFormat from './types' #8714

Closed
ibarapascal opened this issue Mar 25, 2020 · 8 comments
Closed

Comments

@ibarapascal
Copy link

ibarapascal commented Mar 25, 2020

Describe the bug

create-react-app with typescript, yarn start failed

Did you try recovering your dependencies?

NaN

Which terms did you search for in User Guide?

NaN

Environment

NaN

Steps to reproduce

npx create-react-app my-app --template typescript
cd my-app
yarn start

Expected behavior

Start normally

Actual behavior

Reproduced by multiple participants.

TypeScript error in C:/work-place/github/work-repo/my-app/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

Related PR:

It related to package pretty-format: pretty-format/src/index.ts

import style = require('ansi-styles');
import type * as PrettyFormat from './types';

From commit history, we can see there is a related Pull Request two days ago, which changed:

From

import * as PrettyFormat from './types';

To

import type * as PrettyFormat from './types';

Guessing it's related


Related S.O. questions

@ibarapascal ibarapascal changed the title Error import type * as PrettyFormat from './types' create-react-app error: import type * as PrettyFormat from './types' Mar 25, 2020
@ibarapascal
Copy link
Author

ibarapascal commented Mar 25, 2020

Solution

Set Typescript version > 3.8.0 solved this error.

It's a new syntax of Typescript: type-only-imports-and-export

import type { SomeThing } from "./some-module.js";

Document

create-react-app.dev/docs/adding-typescript

yarn add typescript @types/node @types/react @types/react-dom @types/jest

Related QA in Stack Overflow:

@mosesoak
Copy link

@ibarapascal I'm getting the same error on a fresh CRA install using the typescript template (I tried it twice).

Curious why this issue is being closed, rather than updating the typescript version in CRA to prevent the error for others?

Thanks

@SarthakThakur0097
Copy link

yarn add typescript @types/node @types/react @types/react-dom @types/jest

Set Typescript version > 3.8.0 solved this error.

How does this work, the latest stable release version of TypeScript is 3.7.5?

@riccardogiorato
Copy link

Hey @ibarapascal why did you close this issue? I'm having the same problem and your fix:
yarn add typescript @types/node @types/react @types/react-dom @types/jest
was able to solve the crash on compile! You should resume this issue to let the devs fix this issues!

@ibarapascal ibarapascal reopened this Mar 26, 2020
@SarthakThakur0097
Copy link

I rarely agree, since it's not my fix, it's been written in the document.
The reason why this occurs is that if you don't run yarn add typescript, the local version (on your machine) of typescript would be used, which may still lower than 3.8.0.
It's not related to CRA in my opinion.
But, since this kind of talk is keeping active, I would like to OPEN it and let others decide.

Only using this comand: yarn add typescript @types/node @types/react @types/react-dom @types/jest didn't resolve my issue. Is there anything we need to change in the package.json?

@ibarapascal
Copy link
Author

@SarthakThakur0097 You can manually change the Typescript version in your package.json then run npm install or yarn install again.

@SimenB
Copy link
Contributor

SimenB commented Mar 26, 2020

Fix published in 25.2.1, sorry about the inconvenience.

@SarthakThakur0097
Copy link

@ibarapascal

Great thanks that fixed it

psatler added a commit to psatler/be-the-hero that referenced this issue Mar 28, 2020
@lock lock bot locked and limited conversation to collaborators Apr 2, 2020
tiagob added a commit to tiagob/create-full-stack that referenced this issue Sep 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants