首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Visual Studio 2019中使用TypeScript配置ESLint

在Visual Studio 2019中使用TypeScript配置ESLint
EN

Stack Overflow用户
提问于 2020-08-20 21:06:50
回答 1查看 468关注 0票数 1

我正在尝试在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文件。

代码语言:javascript
复制
---
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完成的操作。正如你在下面看到的。

代码语言:javascript
复制
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  
EN

回答 1

Stack Overflow用户

发布于 2021-09-29 10:11:04

我有几乎完全相同的问题,感谢@Qurben评论链接的文章,我通过以下方式解决了这个问题:

  1. 降级到ESLint 6.8,因为ESLint 7需要Node.js 12,而较早版本的Visual Studio 2019运行Node.js 8。这可能不再是必要的。
  2. parserOptions.tsconfigRootDir = __dirname添加到.eslintrc.js (如this instruction中所示。请注意,这在.eslintrc.yml或.eslintrc.json.

中可能不起作用

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63505806

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档