create-react-app error: import type * as PrettyFormat from './types'
See original GitHub issueDescribe 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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:14
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Ask Question - Stack Overflow
import type * as PrettyFormat from './types';. This seems to be the cause of the error. Share.
Read more >[Solved]-create-react-app error import type * as PrettyFormat ...
Coding example for the question create-react-app error import type * as PrettyFormat from './types' in pretty-format-Reactjs.
Read more >'=' expected. TS1005 Very first test start of npm start? : r/reactjs
I have done nothing other than "npx create-react-app client --template typescript" ... 7 | import type * as PrettyFormat from './types';.
Read more >Cannot use import statement outside a module [React ...
This error mainly occurs when you use the import keyword to import a module in Node.js. Or when you omit the type="module" attribute...
Read more >How to use TypeScript with React 18 alpha - LogRocket Blog
Property 'createRoot' does not exist on type 'typeof import("/code/my-app/node_modules/@types/react-dom/index")'. TS2339.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Solution
Set Typescript version > 3.8.0 solved this error.
It’s a new syntax of Typescript: type-only-imports-and-export
Document
create-react-app.dev/docs/adding-typescript
Related QA in Stack Overflow:
@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