Reputation: 1377
I am using WebStorm 5.0.4 to develop a node.js app.
I installed several node modules globally using
npm install -g module-nameand linked them into the project using
npm link module-name
Autocompletion does not work for any of the npm installed modules. It only works for core modules (e.g. http
or path
).
Furthermore, WebStorm gives a warning "Unresolved function or method xyz" for any of the functions I call from npm installed modules.
How do I make WebStorm autocomplete and generally become aware of the installed modules that I require
?
Upvotes: 11
Views: 13755
Reputation: 6214
My answer works only on WebStorm 7 onwards:
Open the Settings dialog (File | Default Settings) and select JavaScript | Node.js.
Specify the path to Node.js interpreter and the Node.js version will be determined automatically.
Click Configure and then click the ‘Download and Configure’ button to download Node.js sources to the IntelliJ system local folder. A JavaScript library named “Node.js v. Core Library” will be created from the extracted source files of core modules.
Finally define a usage scope for JavaScript library just created. By default the whole project will be added to the usage scope. If that does not work for you, you can tune the usage scope by clicking the ‘Edit usage scope’ hyperlink.
If you need more information, read up on JetBrain's Official Blog on Attaching the sources of Node.js core modules, that should ideally solve your problem, it actually did for me at least.
Upvotes: 2
Reputation: 3803
This happens when you declare multiple modules with a comma such as:
var sys = require("sys"),
http= require("http");
in the example above sys will only have exports as an auto complete option where as http will work fine. If you do:
var sys = require("sys");
var http= require("http");
both sys and http will work fine.
Upvotes: 0
Reputation: 181
I'm not sure if this accounts for your particular situation, however I ran into a similar issue in WebStorm 5.0.4, whereas anything that was required was not auto-completing. I was able to resolve this issue by going into my Project Settings, navigating to JavaScript | Libraries, checking "Node.js Core Modules" and "Node.js Globals", and clicking apply.
Upvotes: 18
Reputation: 38499
As per the link I posted in the comments, you'll need to add your global npm directory using
Preferences -> Directories
You can find out where your global directory is by running:
> npm ls -g
Source: http://youtrack.jetbrains.com/issue/WEB-1880
Upvotes: 2