我正在使用“eslint --fix on save”功能。昨天它停止工作了。但它在终端中仍然运行良好。此问题仅出现在WebStorm中。
IDE 返回错误:
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"
}
}
<?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>
我尝试手动更新 WebStorm ESLint 配置,但没有任何改变。
有什么想法吗?
尝试将 ESLint 设置更改为 手动配置,并按照 https://www.jetbrains.com/help/webstorm/2021.1/eslint.html#ws_js_eslint_manual_configuration
中所述显式指定 ESLint 工作目录