webstorm中使用express的方法出现unresolved function or method

问题描述

在Webstorm中使用express的方法时出现unresolved function or method get()

webstorm中使用express的方法出现unresolved function or method

解决办法

官网给出的方法

这些属性是在运行时动态添加的,并没有在Express模块中定义,所以Webstorm无法使用静态分析而报错。可通过安装@types/express解决。

光标选中require('express')中的express,然后Alt+Enter,在弹出的窗口中选择Install TypeScript definitions for better type information,安装完成即可。

webstorm中使用express的方法出现unresolved function or method

这时候,再JavaScript的Libaries中就有了@types/express。若在别的项目中再次出现此类情况,只要将该库选上即可。

此类情况,只要将该库选上即可。

webstorm中使用express的方法出现unresolved function or method