Almost for all third-party modules WebStorm's autocomplition cannot resolve methods/fields. Under autocompletion I mean also all intellisense-like features. For example:
var async = require('async');
async.series() //WebStorm's tooltip says: Unresolved function or method series()
At the same time it resolves
async.exports.series().
But this leads to runtime error:
TypeError: Cannot call method 'series' of undefined
For my own modules I've found workaround. If I do in the module:
var myModule = module.exports;
myModule.someMethod = function(){
...
}
Then autocomplition for someMethod works fine.
Regarding all of above I have a bunch of questions.
1. Why the ide fails to resolve async.series()?
2. Why async.exports.series() leads to runtime error?
3. How to make autocomplition work?
WebStorm 5.0.4.
Go to Settings -> JavaScript -> Libraries -> Check "Node.js Globals"
New WebStorm v7 has ability to define Typescript community stubs for popular modules. This partially solves the problem with autocompletion and IDE warnings.
For less popular modules I prefer to use this ugly cheat:
//noinspection ConstantConditionalExpressionJS,JSPotentiallyInvalidConstructorUsage
var async = false ? new require('async') : require('async');
However, this doesn't solves the problem, when property been attached to module by some algorithm (for example iterating filesystem). For small and unpopular modules it is a rare case.
BTW, async has already typescript stub in [email protected]:borisyankov/DefinitelyTyped.git repository.
Use new as follows:
var async = new require('async');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With