'React' was used before it was defined

前端 未结 14 2002
傲寒
傲寒 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:59

    If you are only getting this error for .js files, make sure @typescript-eslint/parser is being used exclusively on Typescript files.

    .eslintrc.json (abbreviated)

    {
      "overrides": [
        {
          "files": ["**/*.ts", "**/*.tsx"],
          "plugins": ["@typescript-eslint"],
          "rules": {
            "no-use-before-define": "off",
            "@typescript-eslint/no-use-before-define": ["error"],
          },
        }
      ],
      // WRONG: Do not use @typescript-eslint/parser on JS files
      // "parser": "@typescript-eslint/parser",
      "plugins": [
        "react",
        // "@typescript-eslint"
      ],
    }
    

提交回复
热议问题