【问题标题】:EsLint: Parsing error: Invalid value for lib provided: es2021EsLint:解析错误:提供的 lib 值无效:es2021
【发布时间】:2020-12-23 19:11:39
【问题描述】:

我尝试在我的React/TypeScript project 之一中实现 eslint。我使用 eslint 的 cli yarn eslint --init 和 airbnb 配置创建了我的 .eslintrc.js

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

但是当我运行 eslint 时,我的所有 .tsx 文件都会出现此错误:

0:0 错误解析错误:提供的 lib 值无效:es2021

我所有的文件都以 React 的导入开始:

import * as React from 'react';
...

作为某人知道问题是什么?

【问题讨论】:

  • 如果您使用整个 AirBnB 规则集,我怀疑您会遇到大量不兼容的规则。没有在考虑 Typescript 的情况下指定它。

标签: javascript reactjs typescript eslint


【解决方案1】:

在您的存档 .eslintrc.js 中,将“parseOption”更改为:

"parserOptions": {
  ...,
  "ecmaVersion": 2020
},

【讨论】:

    猜你喜欢
    • 2017-03-01
    • 2016-07-25
    • 2017-10-11
    • 2019-12-25
    • 2022-11-11
    • 2016-03-11
    • 1970-01-01
    • 2021-06-10
    • 2016-08-10
    相关资源
    最近更新 更多