简体   繁体   English

WebStorm 中 node.js 的 Intellisnese

[英]Intellisnese for node.js in WebStorm

I'm having trouble with intellisense in WebStorm for express package and also for sequelize package.我在 WebStorm 中遇到智能感知问题,用于快速 package 以及续集 package。 I have also tried VS code and problem there is same.我也尝试过 VS 代码,问题也一样。 For example with imported package例如用进口的package

const express = require('express');
const app = express();

then I get no suggestion for app.get() or any other method.然后我没有得到关于app.get()或任何其他方法的建议。 Even worst I get the get() method underline in WebStorm with warning saying Unresolved method or function更糟糕的是,我在 WebStorm 中get()方法下划线,并警告说Unresolved method 或 function

在此处输入图像描述

Code runs fine though.代码运行良好。 There are also other problems with other packages like sequelize.其他软件包(如 sequelize)也存在其他问题。 I kinda managed to fixed express intellisense by adding.application in import which however crash the app我有点设法通过在导入中添加.application 来修复 Express intellisense,但会使应用程序崩溃

const express = require('express').application;

Another approach I tried was to add enable after initialisation.我尝试的另一种方法是在初始化后添加启用。 That doesn't crash the app and intellisense start works even warning is gone即使警告消失,这也不会使应用程序崩溃并且智能感知启动工作正常

const app = express().enable();

I know this works for others by watching video online.通过在线观看视频,我知道这对其他人有用。 Nobody had to add anything into import or initialisation to make that intellisense work so I guess there is some problem with setting and I just can't figure out what it is没有人必须在导入或初始化中添加任何东西来使智能感知工作,所以我猜设置有一些问题,我只是不知道它是什么

Here are some pictures of my stetting这是我的一些照片

在此处输入图像描述

在此处输入图像描述

Adding TypeScript definition files usually helps IDEs to resolve methods that are otherwise hard to resolve based on the static code analysis.添加 TypeScript 定义文件通常有助于 IDE 解决基于 static 代码分析难以解决的方法。

In WebStorm, you can press Alt-Enter on require('express') and select Install TypeScript definitions for better type information – this will download @types/express and configure it in the IDE.在 WebStorm 中,您可以在require('express')和 select 上按 Alt-Enter安装 TypeScript 定义以获得更好的类型信息——这将下载@types/express并在 Z581D6381F3F35E4F9DZF8B6732 中配置它。 Alternatively, you can add @types/express to your package.json file.或者,您可以将@types/express添加到 package.json 文件中。

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

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