如何修复Typescript linting在VSCode中不起作用?

问题描述

在我的settings.json中,我有

"eslint.validate": [
    "javascript","javascriptreact","typescript","typescriptreact"
  ]

但是我的打字稿支持不起作用。它会在运行时捕获错误,但不会显示红色的波浪线(下面的示例)。

启用ESLint时也会出现错误,并且启用ESLint时Prettier不起作用:

ESLint: Failed to load parser '@typescript-eslint/parser' declared in 'template/.eslintrc.js': Cannot find module 'typescript' Require stack: - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/@typescript-eslint/typescript-estree/dist/parser.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/@typescript-eslint/typescript-estree/dist/index.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/@typescript-eslint/parser/dist/parser.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/@typescript-eslint/parser/dist/index.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/eslint/lib/cli-engine/config-array-factory.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/eslint/lib/cli-engine/cascading-config-array-factory.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/eslint/lib/cli-engine/cli-engine.js - /Users/henryboisdequin/Desktop/MyAwesomeProject/node_modules/eslint/lib/cli-engine/index.j

如何解决此问题?

enter image description here

解决方法

您可以按照以下步骤修复打字稿

您还可以尝试检查TypeScript服务器日志以查看TSLint无法正常工作的原因:

  • 在VS Code用户或工作空间设置中,设置 “ typescript.tsserver.log”:“简洁”
  • 打开您认为应该启用TSLint的TS文件。
  • 在VS Code命令面板中,运行TypeScript:打开TS Server日志。
,

解决此问题的方法是按照以下步骤操作:

  1. 关闭VSCode

  2. 将CD放入应用程序

/Users/<user>/Library/Application\ Support
  1. 检查VSCode文件夹的位置(查找它是code /还是.vscode /)
ls
  1. 删除VSCode文件夹
rm -rf code/ or .vscode/
  1. 打开VSCode-应该在那里有所有扩展名,但是诸如主题,扩展名设置之类的东西不会配置-

  2. 现在所有内容(扩展设置,主题等)将被重置