'React' was used before it was defined

前端 未结 14 2146
傲寒
傲寒 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条回答
  •  猫巷女王i
    2020-12-29 19:55

    Try adding import/resolver to your Eslint settings:

      "settings": {
        "react": { "version": "detect" },
        "import/resolver": { "typescript": {} }
      }
    

    Maybe you will need to install it too:

    $ yarn add -D eslint-import-resolver-typescript
    

    If that doesn't work, you could change this rule

    "@typescript-eslint/no-use-before-define": "off"
    

    like this:

    "no-use-before-define": "off"
    

提交回复
热议问题