【问题标题】:eslint fails with Cannot read config file: /some/path/node_modules/@typescript-eslint/eslint-plugin/dist/configs/eslint-recommendedeslint 失败,无法读取配置文件:/some/path/node_modules/@typescript-eslint/eslint-plugin/dist/configs/eslint-recommended
【发布时间】:2020-11-20 01:37:58
【问题描述】:

我正在按照说明从 here 设置 ESLint。

ESLint 失败并显示以下消息:

$ npm run lint

> IACS@1.0.0 lint /some/path/sscce-typescript-react-eslint
> eslint '*/**/*.{js,ts,tsx}' --quiet --fix

Error: Cannot read config file: /some/path/sscce-typescript-react- 
eslint/node_modules/@typescript-eslint/eslint-plugin/dist/configs/eslint-recommended
Error: ENOENT: no such file or directory, open '/some/path/sscce-typescript-react- 
eslint/node_modules/@typescript-eslint/eslint-plugin/dist/configs/eslint-recommended'
Referenced from: /some/path/sscce-typescript-react-eslint/node_modules/@typescript- 
eslint/eslint-plugin/dist/index.js
Referenced from: /some/path/sscce-typescript-react-eslint/.eslintrc.js

确实存在具有以下名称的文件:

/some/path/sscce-typescript-react-eslint/node_modules/@typescript-eslint/eslint-plugin/dist/configs/eslint-recommended.js

...但显然 ESLint 没有预料到 *.js 扩展名并且找不到该文件。

this github repo 中可以找到最短的独立具体示例。

为了本网站的完整性,我的package.json 是:

{
  "name": "IACS",
  "version": "1.0.0",
  "description": "react, typescript",
  "main": "index.js",
  "scripts": {
    "dev": "webpack-dev-server --hot --inline --devtool source-map --progress --colors  --port 8090",
    "lint": "eslint '*/**/*.{js,ts,tsx}' --quiet --fix"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.8.7",
    "@babel/plugin-proposal-class-properties": "^7.8.7",
    "@babel/plugin-transform-async-to-generator": "^7.8.7",
    "@babel/preset-env": "^7.8.7",
    "@babel/preset-react": "^7.8.7",
    "@babel/register": "^7.8.7",
    "@babel/runtime": "^7.8.7",
    "@types/jquery": "^3.5.1",
    "@types/react": "^16.9.40",
    "@types/react-dom": "^16.9.8",
    "@typescript-eslint/eslint-plugin": "^3.7.1",
    "@typescript-eslint/parser": "^3.7.1",
    "babel-loader": "^8.0.5",
    "cross-env": "^5.2.0",
    "css-loader": "^2.1.0",
    "eslint": "^5.16.0",
    "eslint-config-airbnb": "^17.1.0",
    "eslint-plugin-import": "^2.15.0",
    "eslint-plugin-jsx-a11y": "^6.2.0",
    "eslint-plugin-react": "^7.20.5",
    "file-loader": "^3.0.1",
    "html-webpack-plugin": "^3.2.0",
    "null-loader": "^0.1.1",
    "react-hot-loader": "^4.6.3",
    "ts-loader": "^7.0.5",
    "typescript": "^3.9.5",
    "webpack": "^4.29.0",
    "webpack-cli": "^3.3.*",
    "webpack-dev-server": "^3.1.14"
  },
  "dependencies": {
    "@babel/polyfill": "^7.8.7",
    "jquery": "^3.5.1",
    "react": "^16.8.0",
    "react-dom": "^16.9.8"
  }
}

而我的.eslintrc.js 是:

module.exports = {
    parser: "@typescript-eslint/parser",
    "plugins": ["@typescript-eslint"],
  parserOptions: {
    ecmaVersion: 2020,
    sourceType: "module",
    ecmaFeatures: {
      jsx: true
    }
  },
  settings: {
    react: {
      version: "detect"
    }
  },
  extends: [
    "plugin:react/recommended",
    "plugin:@typescript-eslint/recommended"
  ],
  rules: {
      "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"]
  },
};

【问题讨论】:

    标签: typescript webpack eslint


    【解决方案1】:

    我最近在windows下遇到了同样的问题,将package.json中的eslint依赖更新为

    "eslint": "^7.6.0"
    

    解决了这个问题。 我希望这对您来说也是一个可行的解决方案。

    【讨论】:

      【解决方案2】:

      就我而言,问题是我最近更新了 eslint 的版本,而 VSCode 仍在尝试加载旧版本(不知道为什么)。我通过重新加载窗口解决了这个问题:

      1. SHIFT+CMD+P
      2. 点击“开发者:重新加载窗口”

      【讨论】:

        猜你喜欢
        • 2023-03-14
        • 2019-07-30
        • 2019-06-28
        • 2023-01-17
        • 2020-07-16
        • 2021-07-01
        • 2022-06-16
        • 2019-01-08
        • 2016-05-27
        相关资源
        最近更新 更多