Error: .eslintrc.js » eslint-config-standard: Environment key “es2021“ is unknown 版本兼容问题

Error: .eslintrc.js » eslint-config-standard: Environment key "es2021" is unknown

  • 原因分析
  • 解决方案

原因分析

在 Gulp 中集成 ESLint,安装 gulp-eslint 插件、eslint 模块,并且在 gulpfile.js 中使用gulp-eslint 插件,在运行 gulp 中的注册任务时,报出如下错误:

C:\Exercises\eslint-gulp>yarn gulp script
yarn run v1.22.10
$ C:\Exercises\eslint-gulp\node_modules\.bin\gulp script
[09:27:10] Using gulpfile ~\eslint-gulp\gulpfile.js
[09:27:10] Starting 'script'...
[09:27:10] 'script' errored after 867 ms
[09:27:10] Error: .eslintrc.js » eslint-config-standard:
        Environment key "es2021" is unknown

    at C:\Exercises\eslint-gulp\node_modules\gulp-eslint\node_modules\eslint\lib\shared\config-validator.js:169:19
    at Array.forEach (<anonymous>)
    at validateEnvironment (C:\Exercises\eslint-gulp\node_modules\gulp-eslint\node_modules\eslint\lib\shared\config-validator.js:163:30)
    at validateConfigArray (C:\Exercises\eslint-gulp\node_modules\gulp-eslint\node_modules\eslint\lib\shared\config-validator.js:334:9)
    at CascadingConfigArrayFactory._finalizeConfigArray (C:\Exercises\eslint-gulp\node_modules\gulp-eslint\node_modules\eslint\lib\cli-engine\cascading-config-array-factory.js:417:13)
    at CascadingConfigArrayFactory.getConfigArrayForFile (C:\Exercises\eslint-gulp\node_modules\gulp-eslint\node_modules\eslint\lib\cli-engine\cascading-config-array-factory.js:271:21)
    at CLIEngine.isPathIgnored (C:\Exercises\eslint-gulp\node_modules\gulp-eslint\node_modules\eslint\lib\cli-engine\cli-engine.js:951:18)
    at Transform._transform (C:\Exercises\eslint-gulp\node_modules\gulp-eslint\index.js:43:14)
    at Transform._read (_stream_transform.js:191:10)
    at Transform._write (_stream_transform.js:179:12)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

上面的错误,是由于,eslint-config-standard 中 不识别 es2021 的运行环境。也就是说,gulp-eslint 、eslint 和 eslint-config-standard 版本不兼容。

模块版本,如下所示:

 "eslint": "^7.14.0",
 "eslint-config-standard": "^16.0.2",
 "gulp-eslint": "^6.0.0",

解决方案

下面,修改 eslint-config-standard 的版本。

$ yarn add eslint-config-standard@14.1.1 eslint-plugin-standard --dev

注意

[email protected]: standard 16.0.0 and eslint-config-standard 16.0.0 no longer require the eslint-plugin-standard package.

即:standard 16.0.0 和 eslint-config-standard 16.0.0 不再要求安装 eslint-plugin-standard 依赖。

你可能感兴趣的:(Bug,集锦,gulp)