我正在尝试在Visual Studio2019中配置ESLint,我在选项中启用了ESLint,并且我已经在我的项目中的node_modules中安装了ESLint 7.4.0,这应该会导致Visual Studio根据this document使用该版本。但这会导致一个不太有用的错误。
当在命令行中从.eslintrc.yml文件所在的目录运行eslint .时,它会正常工作,并且会报告有关我的代码的错误和警告。
在Visual Studio中查看.js、.ts或.tsx文件时,它会在文件的第一个字符处报告以下错误internal-error: (ESLint) Unexpected token {。不报告任何其他错误(其中命令行会报告错误)。Visual Studio会在这些文件中报告常见的智能感知TypeScript错误。

以下是我的.eslintrc.yml文件。
---
parser: "@typescript-eslint/parser" # Specifies the ESLint parser
parserOptions:
ecmaFeatures:
jsx: true # Allows for the parsing of JSX
settings:
react:
version: detect # Tells eslint-plugin-react to automatically detect the version of React to use
extends:
- plugin:react/recommended # Uses the recommended rules from @eslint-plugin-react
- plugin:react-hooks/recommended # Uses the recommended rules from @eslint-plugin-react-hooks
- plugin:@typescript-eslint/recommended # Uses the recommended rules from the @typescript-eslint/eslint-plugin有没有办法查看Visual Studio正在执行的内容以及导致此错误的原因?
我试着运行devenv.exe /log,但没有记录任何有趣的东西,只记录了一些使用eslint完成的操作。正如你在下面看到的。
821 Begin export of category 'TypeScript_EsLint' ({d5d56c12-87c4-46f2-894f-3a75ee781f48}) from package 'Microsoft.VisualStudio.LanguageServices.TypeScript.TypeScriptPackage, Microsoft.VisualStudio.LanguageServices.TypeScript, Version=16.0.0.0, Culture=neutral' ({2FFE45C4-5C73-493C-B187-F2E955FF875E}). 3095452 KB of virtual memory currently available. Profile manager 2020/08/19 08:11:21.001
822 End export of category 'TypeScript_EsLint' ({d5d56c12-87c4-46f2-894f-3a75ee781f48}) from package 'Microsoft.VisualStudio.LanguageServices.TypeScript.TypeScriptPackage, Microsoft.VisualStudio.LanguageServices.TypeScript, Version=16.0.0.0, Culture=neutral' ({2FFE45C4-5C73-493C-B187-F2E955FF875E}). 3095452 KB of virtual memory currently available. Profile manager 2020/08/19 08:11:21.003 发布于 2021-09-29 10:11:04
我有几乎完全相同的问题,感谢@Qurben评论链接的文章,我通过以下方式解决了这个问题:
parserOptions.tsconfigRootDir = __dirname添加到.eslintrc.js (如this instruction中所示。请注意,这在.eslintrc.yml或.eslintrc.json.中可能不起作用
https://stackoverflow.com/questions/63505806
复制相似问题