'React' was used before it was defined

前端 未结 14 2145
傲寒
傲寒 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 19:54

    The bug occurs due to mismatch of @typescript-eslint versions in react-scripts and your local package.json - GitHub issue

    You can downgrade the packages until react-scripts updates their version.

        "@typescript-eslint/eslint-plugin": "4.0.1",
        "@typescript-eslint/parser": "4.0.1",
    

    EDIT 14/09/2020

    It seems the bug is not related to react-scripts version of @typescript-eslint since multiple people reported the same bug without using react-scripts.

    Anyway, the workaround remains the same - downgrade to the working version of @typescript-eslint until the fix is available.

    EDIT 24/10/2020

    react-scripts@4.0.0 has been published with updated @typescript-eslint. Using the newest version should solve the issue.

    EDIT 04/11/2020

    If after upgrading the packages the error is still there, most probably your eslint config uses the wrong rule. Check out Igor's answer to fix it.

提交回复
热议问题