簡體   English   中英

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

[英]How to fix Typescript linting not working in 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

我該如何解決這個問題?

在此處輸入圖片說明

解決此問題的方法是按照以下步驟操作:

  1. 關閉 VSCode

  2. 光盤進入應用程序

/Users/<user>/Library/Application\ Support
  1. 檢查 VSCode 文件夾所在的位置(查找是 code/ 還是 .vscode/)
ls
  1. 刪除VSCode文件夾
rm -rf code/ or .vscode/
  1. 打開 VSCode - 那里應該有你所有的擴展,但是像你的主題這樣的東西,擴展設置不會被配置 -

  2. 現在一切(擴展設置、主題等)都將被重置

您可以按照以下步驟修復打字稿

您還可以嘗試檢查 TypeScript 服務器日志以了解 TSLint 不工作的原因:

  • 在你的 VS Code 用戶或工作區設置中,設置 "typescript.tsserver.log": "terse"
  • 打開您認為應該啟用 TSLint 的 TS 文件。
  • 在 VS Code 命令面板中,運行 TypeScript: Open TS Server Log。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM