简体   繁体   中英

How can I get error highlighting for missing imports in Visual Studio Code?

When working with Visual Studio Code on Windows to develop Angular applications, I recall that if I removed an import statement, vscode would almost immediately underline in red all of the places where those artifacts were being referenced.

However, now I am working in vscode on a Mac to develop React applications, and I've noticed that if I remove an import statement, I do not get any red-underlining like I am used to.

Any thoughts as to how I can get this functionality back? I imagine its due to an Angular package I had installed on my previous workspace, that I no longer have.

By default, VS Code only checks the syntax of JS files and will not complain about undefined variables like it does with TypeScript

You can follow these instructions to enable type checking in plain old JS files. The simplest approach is to add //@ts-check at the top of the file

@Matt Bierner gave a good advice to check instructions , but after reading it I can say that the best option is to create or modify jsconfig.json by adding "checkJs": true

{
  "compilerOptions": {
    "checkJs": true,
  },
  "exclude": ["node_modules", "**/node_modules/*"]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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