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

我正在创建一个新的Next.js应用程序。 当我运行yarn create-next-app并开始在Visual Studio代码中编写Java代码时,ESlint扩展每次输入数字时都会抛出一个错误。 而且,很自然地,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.

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

Eslint extension error on Visual Studio Code

这是我的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"
  }
}

感谢您的帮助。


解决方案

在我的esling.options的内容包装成overrideConfig自己解决,如下所示:

"eslint.options": {
    "overrideConfig": {
      "env": {
        "browser": true,
        "es6": true
      },
      "parserOptions": {
        "ecmaVersion": 2019,
        "sourceType": "module",
        "ecmaFeatures": {
          "jsx": true
        }
      },
      "rules": {
        "no-debugger": "off"
      }
    }
  },

相关文章