如何修复 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
我该如何解决这个问题?
您可以按照步骤修复打字稿
您也可以尝试检查 TypeScript 服务器日志以了解 TSLint 无法工作的原因:
- 在您的 VS Code 用户或工作区设置中,设置
"typescript.tsserver.log": "简洁"
- 打开您认为应该启用 TSLint 的 TS 文件。
- 在 VS Code 命令面板中,运行TypeScript:打开 TS 服务器日志。
解决此问题的方法是按照以下步骤操作:
关闭VSCode
CD 进入应用程序
/Users/<user>/Library/Application\ Support
- 查看VSCode文件夹所在的位置(判断是code/还是.vscode/)
ls
- 删除 VSCode 文件夹
rm -rf code/ or .vscode/
打开 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
我该如何解决这个问题?
您可以按照步骤修复打字稿
您也可以尝试检查 TypeScript 服务器日志以了解 TSLint 无法工作的原因:
- 在您的 VS Code 用户或工作区设置中,设置 "typescript.tsserver.log": "简洁"
- 打开您认为应该启用 TSLint 的 TS 文件。
- 在 VS Code 命令面板中,运行TypeScript:打开 TS 服务器日志。
解决此问题的方法是按照以下步骤操作:
关闭VSCode
CD 进入应用程序
/Users/<user>/Library/Application\ Support
- 查看VSCode文件夹所在的位置(判断是code/还是.vscode/)
ls
- 删除 VSCode 文件夹
rm -rf code/ or .vscode/
打开 VSCode - 那里应该有你所有的扩展,但是像你的主题这样的东西,扩展设置不会被配置 -
现在一切(扩展设置、主题等)都将被重置