create-react-app error import type * as PrettyFormat from './types' in pretty-format

前端 未结 2 1976
南方客
南方客 2021-02-14 02:54

it\'s a fresh install of cra with typescript template running on node 13.11.0 it gives me error when try to run npm start

TypeScript error in D:/Projects/persona         


        
2条回答
  •  故里飘歌
    2021-02-14 03:32

    Update

    Thanks for marcelo-waisman's post.

    Upgrading Typescript to > 3.8.0 solved this.

    If we follow the documentation tightly...

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

    ... we should have installed TypeScript with the latest version, rather than the local-global version which may still below 3.8.0.


    I found some clues. Maybe it's worth an opening an issue.

    It's related to the package pretty-format and its type in create-react-app. We can find the source here: pretty-format/src/index.ts

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

    From the commit history, we can see there is a related Pull Request from two days ago, which changed this part from...

    import * as PrettyFormat from './types';
    

    ... to...

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

    This seems to be the cause of the error.

提交回复
热议问题