Environment key "es2021" is unknown

6.7k Views Asked by At

Sorry for repeating the question, but I am a rookie and didn't understand how to solve this problem. Please, if it is not difficult, describe in more detail how to solve this problem.

I'm creating my learning project using the 2017 textbook and there were no such errors in that code. I can't find the problem on my own due to my inexperience in such complex projects.

enter image description here gulpfile

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"
    }

.eslintrc:

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": {
    }
};
1

There are 1 best solutions below

0
On

I've got it after some changes in

.eslintrc

  1. I've changed "es2021": true, into "es2020": true,
  2. After I've got the error Parsing error: Invalid ecmaVersion I've changed "ecmaVersion": 12, into "ecmaVersion": 11,
  3. And the last one I've checked https://github.com/yannickcr/eslint-plugin-react#recommend and found a solution of how to "enable" all configuration that includes every available rule in this part:
 "extends": [
        "eslint:recommended",
        "plugin:react/recommended",
        "eslint:all", // just added this line
        "plugin:react/all" // and this line
    ],

I'm not sure if this really works, but it looks like it:

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.