Gulp 环境键“es2021”未知[重复]

lh80um4z  于 2022-12-08  发布在  Gulp
关注(0)|答案(1)|浏览(275)

此问题在此处已有答案

gulp-eslint Environment key "es2021" is unknown(3个答案)
6个月前关闭。
很抱歉重复这个问题,但是我是一个新手,不知道如何解决这个问题。如果不是很难,请更详细地描述如何解决这个问题。
我正在用2017年的教科书创建我的学习项目,代码中没有这样的错误。由于我对这样复杂的项目缺乏经验,我无法自己发现问题。


吞咽文件

const gulp = require ('gulp') ;
const babel = require('gulp-babel');
const eslint = require('gulp-eslint');

// Задание для gulp - инструмент сборки.
gulp.task('default', async function ()
{
    // Запуск ESLint
    gulp.src(["es6/**/*.js", "public/es6/**/*.js"])
        .pipe(eslint())
        .pipe(eslint.format());
    // Указание для node.js
    // Указание кода источника для сборки.
    gulp.src("es6/**/*.js")
        // Транспортировка(pipe) файлов исходного кода в Babel, который преобразует их из ЕSб в ES5.
        .pipe(babel())
        // На завершающем этапе откомпилированный код ES5 транспортируется по назначению, в каталог dist.
        .pipe(gulp.dest("dist"));

    // Указание для браузера.
    // Указание кода источника для сборки.
    gulp.src("public/es6/**/*.js")
        // Вызов транскриптора для кода.
        .pipe(babel())
        //На завершающем этапе откомпилированный код ESS транспортируется по назначению, в каталог dist.
        .pipe(gulp.dest("public/dist"));
});

** Package :**

{
      "name": "javascriptproject",
      "version": "1.0.0",
      "description": "myProject",
      "main": "main.js",
      "directories": {
        "test": "test"
      },
      "dependencies": {
        "gulp-eslint": "^6.0.0",
        "save-dev": "0.0.1-security",
        "underscore": "^1.13.1"
      },
      "devDependencies": {
        "@babel/core": "^7.14.6",
        "@babel/preset-env": "^7.14.7",
        "@babel/preset-react": "^7.14.5",
        "babel-preset-es2015": "^6.24.1",
        "eslint": "^7.29.0",
        "eslint-plugin-react": "^7.24.0",
        "gulp": "^4.0.2",
        "gulp-babel": "^8.0.0"
      },
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "repository": {
        "type": "git",
        "url": "D:\\JavaScriptProject"
      },
      "keywords": [
        "my",
        "first",
        "project"
      ],
      "author": "me",
      "license": "ISC"
    }

.电子邮件地址:

module.exports = {
    "env": {
        "browser": true,
        "es2021": true,
        "node": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:react/recommended"
    ],
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 12,
        "sourceType": "module"
    },
    "plugins": [
        "react"
    ],
    "rules": {
    }
};
i34xakig

i34xakig1#

我把它改了一下
.eslintrc
1.我已更改"es2021": true, into "es2020": true,
1.在得到错误Parsing error: Invalid ecmaVersion之后,我修改了"ecmaVersion": 12into "ecmaVersion": 11
1.最后一个我已经检查了https://github.com/yannickcr/eslint-plugin-react#recommend,并找到了一个解决方案,如何“启用”所有配置,包括每个可用的规则在这一部分:

"extends": [
        "eslint:recommended",
        "plugin:react/recommended",
        "eslint:all", // just added this line
        "plugin:react/all" // and this line
    ],

我不确定这是否真的有效,但看起来是这样的:

D:\JavaScriptProject\public\es6\test.js
   1:1   error  'use strict' is unnecessary inside of modules                                    strict
   1:1   error  Strings must use doublequote                                                     quotes
   1:14  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
   2:1   error  Expected space or tab after '//' in comment                                      spaced-comment
   2:40  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
   3:18  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
   4:6   error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
   5:10  error  Extra space after key 'subject'                                                  key-spacing
   5:10  error  Unquoted property 'subject' found                                                quote-props
   5:20  error  Strings must use doublequote                                                     quotes
   5:34  error  Object properties must go on a new line                                          object-property-newline
   5:34  error  Unquoted property 'verb' found                                                   quote-props
   5:40  error  Strings must use doublequote                                                     quotes
   5:46  error  Object properties must go on a new line                                          object-property-newline
   5:46  error  Unquoted property 'object' found                                                 quote-props
   5:46  error  Expected object keys to be in ascending order. 'object' should be before 'verb'  sort-keys
   5:54  error  Strings must use doublequote                                                     quotes
   5:63  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
   6:10  error  Extra space after key 'subject'                                                  key-spacing
   6:10  error  Unquoted property 'subject' found                                                quote-props
   6:20  error  Strings must use doublequote                                                     quotes
   6:33  error  Object properties must go on a new line                                          object-property-newline
   6:33  error  Unquoted property 'verb' found                                                   quote-props
   6:39  error  Strings must use doublequote                                                     quotes
   6:47  error  Object properties must go on a new line                                          object-property-newline
   6:47  error  Unquoted property 'object' found                                                 quote-props
   6:47  error  Expected object keys to be in ascending order. 'object' should be before 'verb'  sort-keys
   6:55  error  Strings must use doublequote                                                     quotes
   6:63  error  Unexpected trailing comma                                                        comma-dangle
   6:64  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
   7:7   error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
   8:1   error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
   9:42  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
  10:1   error  Expected a function expression                                                   func-style
  10:13  error  Missing space before function parentheses                                        space-before-function-paren
  10:38  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
  11:1   error  Opening curly brace does not appear on the same line as controlling statement    brace-style
  11:1   error  Block must be padded by blank lines                                              padded-blocks
  11:2   error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
  12:5   error  Unexpected console statement                                                     no-console
  12:51  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
  13:1   error  Block must be padded by blank lines                                              padded-blocks
  13:2   error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
  14:1   error  Comments should not begin with a lowercase character                             capitalized-comments
  14:26  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
  15:1   error  Expected space(s) after "for"                                                    keyword-spacing
  15:9   error  Identifier name 's' is too short (< 2)                                           id-length
  15:9   error  's' is never reassigned. Use 'const' instead                                     prefer-const
  15:24  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
  16:1   error  Opening curly brace does not appear on the same line as controlling statement    brace-style
  16:1   error  Block must be padded by blank lines                                              padded-blocks
  16:2   error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
  17:12  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
  18:1   error  Block must be padded by blank lines                                              padded-blocks
  18:2   error  Newline required at end of file but not found                                    eol-last

✖ 110 problems (110 errors, 0 warnings)
  100 errors and 0 warnings potentially fixable with the `--fix` option.

相关问题