ESLint:创建下一个应用程序时选项无效

Aug*_*sco 8 javascript eslint visual-studio-code next.js

我正在创建一个新的 Next.js 应用程序。当我运行yarn create-next-app并开始在 Visual Studio Code 中编写 javascript 代码时,ESlint 扩展每次 i 数字都会返回一个错误。当然,eslint 不起作用。

错误是:

ESLint: Invalid Options: - Unknown options: env, parserOptions, rules - 'parserOptions' has been removed. Please use the 'overrideConfig.parserOptions' option instead. - 'rules' has been removed. Please use the 'overrideConfig.rules' option instead.. Please see the 'ESLint' output channel for details.
Run Code Online (Sandbox Code Playgroud)

这是用于立即视觉识别的图像:

Visual Studio Code 上的 Eslint 扩展错误

这是我的package.json文件(Next.js 给出的默认 package.json):

{
  "name": "myApp",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "next": "12.0.7",
    "react": "17.0.2",
    "react-dom": "17.0.2"
  },
  "devDependencies": {
    "eslint": "8.4.1",
    "eslint-config-next": "12.0.7"
  }
}

Run Code Online (Sandbox Code Playgroud)

感谢您的帮助。

Aug*_*sco 19

我自己解决了,将 的内容包装esling.optionsoverrideConfig我的settings.json vscode 文件中,如下所示:

"eslint.options": {
    "overrideConfig": {
      "env": {
        "browser": true,
        "es6": true
      },
      "parserOptions": {
        "ecmaVersion": 2019,
        "sourceType": "module",
        "ecmaFeatures": {
          "jsx": true
        }
      },
      "rules": {
        "no-debugger": "off"
      }
    }
  },
Run Code Online (Sandbox Code Playgroud)


小智 5

这对于大多数人来说可能是显而易见的,但我想添加一个警告。上述配置修复有效,但请确保在用户级别和工作区级别执行此操作。如果 eslint.options json 在用户级别配置中没有 overrideConfig ,它将继续出错。抱歉,如果这是显而易见的,但我只是花了最后一个小时试图理解为什么尽管添加了上述解决方案,但我仍然继续收到无效选项错误,直到我意识到我只在工作区中进行更改。希望这可以让某人免于头痛。