Ключ среды «es2021» неизвестен.
Извините за повторение вопроса, но я новичок и не понимал, как решить эту проблему. Пожалуйста, если не сложно, опишите подробнее, как решить эту проблему.
Я создаю свой учебный проект по учебнику 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"));
});
упаковка:
{
"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 ответ
Получил после некоторых изменений в
.eslintrc
- Я изменился
"es2021": true, into "es2020": true,
- После того, как у меня возникла ошибка
Parsing error: Invalid ecmaVersion
Я изменился"ecmaVersion": 12
,into "ecmaVersion": 11
, - И последнее. Я проверил 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.