简体   繁体   English

使Visual Studio Code识别模块并要求

[英]Make Visual Studio Code recognise module and require

Visual Studio Code underlines require and module keywords in my .js files which I run with Node. Visual Studio Code在与Node一起运行的.js文件中强调了require和module关键字。 How to prevent this from happening? 如何防止这种情况发生?

Since Visual studio code is written in TypeScript you need to download type definitions for nodejs. 由于Visual Studio代码是用TypeScript编写的,因此您需要下载nodejs的类型定义。 To do this click on the text (require/ module) which is underlined. 为此,请单击带下划线的文本(要求/模块)。 Now it would show a yellow bulb. 现在它将显示一个黄色灯泡。

在此处输入图片说明

Now click on that yellow bulb. 现在单击那个黄色灯泡。 A menu should open , select Download type definition for node.d.ts . 应该打开一个菜单, Download type definition for node.d.ts选择Download type definition for node.d.ts Done visual studio code will download the type files for you. 完成的Visual Studio代码将为您下载类型文件。

在此处输入图片说明

Now a typings folder will display in your project folder , remember to add that in your .gitignore file to avoid unnecessary file commit to your git repo 现在, typings文件夹将显示在您的项目文件夹中,请记住将其添加到.gitignore文件中,以避免不必要的文件提交到git repo

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

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