简体   繁体   中英

WebStorm “eslint --fix on save” feature doesn't work. But in terminal ESLint works well

I am using "eslint --fix on save" functionality. Yesterday it stopped working. But it still works well in terminal. This problem appears only in WebStorm.

IDE returns error:

Error: Failed to load plugin '@typescript-eslint' declared in '.eslintrc.json » ./node_modules/gts/#overrides[0]': No valid exports main found for '/Users/yurygrinko/WebstormProjects/lynx-project-app/node_modules/@typescript-eslint/experimental-utils/node_modules/eslint-utils'
Referenced from: /Users/yurygrinko/WebstormProjects/lynx-project-app/node_modules/gts/build/src/index.js

Error: Failed to load plugin '@typescript-eslint' declared in '.eslintrc.json » ./node_modules/gts/#overrides[0]': No valid exports main found for '/Users/yurygrinko/WebstormProjects/lynx-project-app/node_modules/@typescript-eslint/experimental-utils/node_modules/eslint-utils'
Referenced from: /Users/yurygrinko/WebstormProjects/lynx-project-app/node_modules/gts/build/src/index.js
    at resolveExportsTarget (internal/modules/cjs/loader.js:611:9)
    at applyExports (internal/modules/cjs/loader.js:492:14)
    at resolveExports (internal/modules/cjs/loader.js:541:12)
    at Function.Module._findPath (internal/modules/cjs/loader.js:643:22)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:941:27)
    at Function.Module._load (internal/modules/cjs/loader.js:847:27)
    at Module.require (internal/modules/cjs/loader.js:1016:19)
    at require (internal/modules/cjs/helpers.js:69:18)
    at Object.<anonymous> (/Users/yurygrinko/WebstormProjects/lynx-project-app/node_modules/@typescript-eslint/experimental-utils/dist/ast-utils/eslint-utils/astUtilities.js:23:34)
    at Module._compile (internal/modules/cjs/loader.js:1121:30)
Process finished with exit code -1

.eslintrc.json

{
  "extends": "./node_modules/gts/",
  "overrides": [
    {
      "extends": ["plugin:react/recommended", "plugin:react-hooks/recommended"],
      "files": ["*.ts", "*.tsx"],
      "rules": {
        "@typescript-eslint/no-explicit-any": "off",
        "@typescript-eslint/no-shadow": "error",
        "node/no-unpublished-import": "off",
        "no-shadow": "off",
        "react-hooks/exhaustive-deps": "warn",
        "react-hooks/rules-of-hooks": "error",
        "react/prop-types": "off"
      }
    }
  ]
}

tsconfig.json

{
  "extends": "./node_modules/gts/tsconfig-google.json",
  "compilerOptions": {
    "lib": ["dom"],
    "outDir": "build",
    "allowJs": true,
    "skipLibCheck": true,
    "noEmit": true,
    "esModuleInterop": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "module": "esnext",
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"],
    }
  },
  "include": [
    "src/**/*.ts",
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx",
  ],
  "exclude": [
    "node_modules",
    "test/**/*.ts"
  ]
}

package.json

{
  "name": "app",
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "gts lint",
    "clean": "gts clean",
    "compile": "tsc",
    "fix": "gts fix",
    "posttest": "yarn run lint",
  },
  "dependencies": {
    "@apollo/client": "^3.3.6",
    "md5": "^2.3.0"
  },
  "devDependencies": {
    "@graphql-codegen/cli": "^1.20.0",
    "@graphql-codegen/typescript": "^1.20.0",
    "@graphql-codegen/typescript-operations": "^1.17.13",
    "@graphql-codegen/typescript-react-apollo": "^2.2.1",
    "@svgr/webpack": "^5.5.0",
    "@testing-library/react-hooks": "^5.1.2",
    "@types/jest": "^26.0.23",
    "@types/lodash": "^4.14.170",
    "@types/md5": "^2.3.0",
    "@types/multer": "^1.4.5",
    "@types/node": "^14.14.20",
    "@types/react": "^17.0.0",
    "@types/sendgrid": "^4.3.0",
    "@types/styled-components": "^5.1.9",
    "@typescript-eslint/eslint-plugin": "^4.22.1",
    "@typescript-eslint/experimental-utils": "^4.26.1",
    "babel-jest": "^26.6.3",
    "babel-plugin-styled-components": "^1.12.0",
    "dotenv": "^8.2.0",
    "eslint": "^7.28.0",
    "eslint-plugin-react": "^7.23.1",
    "eslint-plugin-react-hooks": "^4.2.0",
    "fauna-gql-upload": "^2.3.0",
    "faunadb": "^4.1.3",
    "gts": "^3.1.0",
    "husky": "^6.0.0",
    "jest": "^26.6.3",
    "jest-junit": "^12.0.0",
    "react-test-renderer": "^17.0.2",
    "typescript": "^4.1.3",
    "winston": "^3.3.3"
  }
}

WebStorm ESLint 配置 .idea/../eslint.xml

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="EslintConfiguration">
    <files-pattern value="{**/*,*}.{ts,tsx}" />
    <option name="fix-on-save" value="true" />
  </component>
</project>

I tried to update WebStorm ESLint configuration manually but it changed nothing.

Any ideas?

Try changing ESLint settings to Manual configuration and specify the ESlint working directory explicitly as described in https://www.jetbrains.com/help/webstorm/2021.1/eslint.html#ws_js_eslint_manual_configuration

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM