简体   繁体   English

为 Visual Studio Code 创建一个“jsconfig.json”文件

[英]Creating a 'jsconfig.json' file for Visual Studio Code

I am fairly new to Visual Studio Code and have been following a tutorial to create Node.js applications with Visual Studio Code.我是 Visual Studio Code 的新手,一直在按照教程使用 Visual Studio Code 创建 Node.js 应用程序。

I need to create a jsconfig.json file, the tutorial informs me that there should be a green lightbulb in the status bar, which will generate the file when clicked on.我需要创建一个jsconfig.json文件,教程告诉我状态栏中应该有一个绿色灯泡,点击它会生成文件。 Unfortunately, I cannot see it and I am pretty sure that it should be showing, considering there is no jsconfig.json file in the 'myExpressApp' folder.不幸的是,我看不到它,我很确定它应该显示,考虑到“myExpressApp”文件夹中没有jsconfig.json文件。 Please see the screenshot...请看截图...

问题截图

Are you on a VSCode insiders build? 你是VSCode内部人员吗?

With recent versions of VSCode, if you are only using JavaScript, a jsconfig.json file is no longer required . 使用最新版本的VSCode,如果您只使用JavaScript, 则不再需要jsconfig.json文件 If none is provided, the root directory will be treated as an implicit JavaScript project. 如果未提供,则根目录将被视为隐式JavaScript项目。

If you are working with TypeScript, you still need a tsconfig.json file. 如果您使用的是TypeScript,则仍需要tsconfig.json文件。 See @Aurora0001's answer for creating this. 请参阅@ Aurora0001的答案来创建它。

I'll update the VSCode documentation/tutorial to reflect this change. 我将更新VSCode文档/教程以反映此更改。

It seems odd that the lightbulb doesn't appear as expected, but you can still generate a jsconfig.json yourself. 看起来奇怪的是灯泡没有按预期显示,但你仍然可以自己生成一个jsconfig.json If you're planning to use TypeScript, you can just run this in your terminal (in the project directory): 如果您打算使用TypeScript,可以在终端中(在项目目录中)运行它:

$ tsc --init

This will create a tsconfig.json file ready for you (you'll need to then add "allowJs": true in that file, because that makes it equivalent to jsconfig.json ). 这将为您创建一个tsconfig.json文件(您需要在该文件中添加"allowJs": true ,因为这使它等同于jsconfig.json )。

You could also just click 'New File', copy in the contents from the tutorial and save. 您也可以单击“新建文件”,复制教程中的内容并保存。 There shouldn't be any detrimental effect to your project by not clicking the lightbulb to do it. 不点击灯泡就可以对您的项目产生任何不利影响。

if you are a node-coder,it's good for you to learn typescript.here is the link http://www.typescriptlang.org/ 如果你是一个节点编码器,你学习打字稿是件好事。链接http://www.typescriptlang.org/

and you can add the tsconfig.json file as the document on the link above. 并且您可以在上面的链接上添加tsconfig.json文件作为文档。 such like the code below 比如下面的代码

let a:number = 1;

ts will substitute js soon. ts将很快取代js。

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

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