简体   繁体   English

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

[英]How to fix Typescript linting not working in VSCode?

In my settings.json, I have:在我的 settings.json 中,我有:

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

Yet my typescript support isn't working.但是我的打字稿支持不起作用。 It catches the errors during runtime but doesn't show a red squiggly line (example below).它在运行时捕获错误,但不显示红色波浪线(下面的示例)。

I also get an error when enabling ESLint and Prettier doesn't work when I enable ESLint:启用 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

How do I fix this problem?我该如何解决这个问题?

在此处输入图片说明

The way to fix this problem is to follow these steps:解决此问题的方法是按照以下步骤操作:

  1. Close VSCode关闭 VSCode

  2. CD into applications光盘进入应用程序

/Users/<user>/Library/Application\ Support
  1. Check where VSCode folder is located (find whether it is code/ or .vscode/)检查 VSCode 文件夹所在的位置(查找是 code/ 还是 .vscode/)
ls
  1. Delete the VSCode folder删除VSCode文件夹
rm -rf code/ or .vscode/
  1. Open up VSCode - there should be all your extensions there but stuff like your theme, extension settings will not be configured -打开 VSCode - 那里应该有你所有的扩展,但是像你的主题这样的东西,扩展设置不会被配置 -

  2. Now everything (extension settings, theme, etc) will be reset现在一切(扩展设置、主题等)都将被重置

You can follow the steps to fix typescript您可以按照以下步骤修复打字稿

You can also try checking the TypeScript server logs to see why TSLint is not working:您还可以尝试检查 TypeScript 服务器日志以了解 TSLint 不工作的原因:

  • In your VS Code user or workspace settings, set "typescript.tsserver.log": "terse"在你的 VS Code 用户或工作区设置中,设置 "typescript.tsserver.log": "terse"
  • Open a TS file that you believe should have TSLint enabled.打开您认为应该启用 TSLint 的 TS 文件。
  • In the VS Code command palette, run TypeScript: Open TS Server Log.在 VS Code 命令面板中,运行 TypeScript: Open TS Server Log。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM