Kar*_*ind 4 webstorm typescript-eslint
我\xe2\x80\x99m 使用 TypeScript 和 ESLint 开发 React 项目。我有以下版本的eslint和typescript-eslint我的 package.json 文件中
"@typescript-eslint/eslint-plugin": "^6.3.0",\n"@typescript-eslint/parser": "^6.0.0",\n"eslint": "^8.45.0",\nRun Code Online (Sandbox Code Playgroud)\n我也有以下.eslintrc.cjs文件:
/* eslint-env node */\n\nmodule.exports = {\n root: true,\n env: { browser: true, es2020: true },\n extends: [\n \'eslint:recommended\',\n \'plugin:@typescript-eslint/recommended\',\n \'plugin:@typescript-eslint/recommended-requiring-type-checking\',\n \'plugin:react-hooks/recommended\',\n ],\n parser: \'@typescript-eslint/parser\',\n parserOptions: {\n ecmaVersion: \'latest\',\n sourceType: \'module\',\n project: true,\n tsconfigRootDir: __dirname,\n },\n plugins: [\'react-refresh\'],\n rules: {\n \'react-refresh/only-export-components\': [\n \'warn\',\n { allowConstantExport: true },\n ],\n \'@typescript-eslint/no-non-null-assertion\': \'off\',\n "@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],\n },\n}\nRun Code Online (Sandbox Code Playgroud)\n对于 WebStrom 中的每个文件,我收到以下错误:
\n\n\nSyntaxError: 无法加载在 \'.eslintrc.cjs\' 中声明的插件 \'@typescript-eslint\': 意外的标记 \'.\'
\n
我尝试将我的 Node 版本更新到 20.5.1,重新安装所有依赖项,并验证我的.eslintrc.cjs文件,但似乎没有任何效果。我使用相同文件的同事没有遇到任何问题。
我也尝试了这里的所有解决方案。
\n有谁知道可能导致此错误的原因以及如何修复它?任何帮助,将不胜感激。
\n终于找到解决办法了,是IDE的问题
查找项目使用的节点版本
node --version
Run Code Online (Sandbox Code Playgroud)
对 IDE 解释器使用相同的节点版本
文件 -> 设置 -> 语言和框架 -> Node.js
如果问题仍然存在,您可以从 Webstorm 安装插件并从操作栏重新启动 eslint 服务
| 归档时间: |
|
| 查看次数: |
1995 次 |
| 最近记录: |