简体   繁体   English

PhpStorm:NodeJS模块的未解决的变量,方法和函数

[英]PhpStorm: Unresolved variables, methods & functions for NodeJS modules

I just started a new NodeJS application in PhpStorm which uses some external packages. 我刚刚在PhpStorm中启动了一个新的NodeJS应用程序,该应用程序使用了一些外部软件包。 Unfortunately I see a lot of Unresolved variable or Unresolved function or method warnings: 不幸的是,我看到很多Unresolved variable或未Unresolved function or method警告:

在此处输入图片说明

Obviously this is very distracting. 显然,这很让人分心。 Can I somehow manually tell the IDE to load some definition files of the external packages I use (eg mongoose in this example)? 我可以以某种方式手动告诉IDE加载我使用的外部包的某些定义文件(例如,在此示例中为mongoose )吗?

If I find no other solution I'd simply disable those inspections which is kind of a bad "fallback" since they usually provide some good hints for typos etc. 如果没有其他解决方案,我将禁用这些检查,这是一个不好的“后备”,因为它们通常会为错别字等提供一些很好的提示。


Solution: 解:
I had 2 different node_modules directories in my project: 我的项目中有2个不同的node_modules目录:

project\client\node_modules\...
project\server\node_modules\...

Both were marked as excluded . 两者都被标记为已excluded I simply removed the excluded mark (right-click on the folder in the project tree). 我只是删除了excluded标记(右键单击项目树中的文件夹)。 PhpStorm shows correct auto completion now and the Unresolved warnings are gone. PhpStorm现在显示正确的自动完成,并且Unresolved警告消失了。

If you have jetbrains suite, It's better to use webstorm for nodejs application. 如果您有jet​​brains套件,最好将webstorm用于nodejs应用程序。

However, if you want to keep phpstorm. 但是,如果要保留phpstorm。 You can use a jshint module for global variables declaration, and use jsdoc for variable instance : 您可以将jshint模块用于全局变量声明,并将jsdoc用于变量instance:

/**
 * Description
 * @type {Schema}
 * @property {object} methods
 */
var Schema;

-- EDIT -- -编辑-

Have you set up your phpstorm as the jetbrains doc ? 您是否已将phpstorm设置为jetbrains文档? Work on nodejs with phpstorm 使用phpstorm处理Node.js

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

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