'React' was used before it was defined

前端 未结 14 2115
傲寒
傲寒 2020-12-29 19:28

I am working with create-react-app + typescript + eslint application and during build have such error:

Line 1:8:  \'React\' was used before it was defined  @t         


        
14条回答
  •  庸人自扰
    2020-12-29 20:07

    I landed on this page after I started getting issues with a Gatsby project that was using Typescript and an ESLint config that extended eslint-config-airbnb-typescript. In addition to OP's error, ESLint was also giving errors on various rules not being defined, like Definition for rule '@typescript-eslint/no-redeclare' was not found. and a few others.

    The underlying problem ended up being that Gatsby was using fairly old versions of both @typescript-eslint/eslint-plugin and @typescript-eslint/parser. Forcing yarn to install only up-to-date versions solved the issue:

    // package.json
    "resolutions": {
        "@typescript-eslint/eslint-plugin": "^4.4.0",
        "@typescript-eslint/parser": "^4.4.0"
    }
    

提交回复
热议问题