WebStorm - Unresolved function or method

Hi,
I am fairly new to WebStorm so apologies if this is a trivial question.

I have a project with a root folder of App. The main JavaScript source is in sub-folders under App\www and the test scripts are in sub-folders under App\test.

In particular, I have some unit tests in the following location:
App\test\unit\servicesSpec.js

which uses functions/methods in the following file:
App\test\lib\angular\angular-mocks.js

The references in the servicesSpec.js to functions in angular-mocks.js are all flagged as 'Unresolved function or method' in the editor window for servicesSpec.js.

I assumed that WebStorm would search all the JavaScript files in the project for references but maybe not.
How do I get the references to be resolved ?

Many thanks

3 comments
Comment actions Permalink

Please can you provide a code sample that shows up the issue?


0
Comment actions Permalink

Hi,

when I tried to create a code sample I realised that of course WebStorm is picking up JavaScript references in files in other folders and that the unresolved references are in fact in a node npm package, karma-jasmine, that is installed globally - my bad. The node package is visible in the File->Settings->Node.js and npm along with several other node npm packages that are being used in the project.

So my question really is:

Does WebStorm not resolve references to node npm packages by default and if not, can I manually configure it so that it is able to resolve the references ?

Many thanks

0
Comment actions Permalink

WebStorm only resolves references to those modules that are installed locally (in the project local node_modules folder)
If you like global modules being resolved as well, try adding the corresponding node_modules folders as javascript libraries in Settings/JavaScript/Libraries
However I'd really suggest using typescript community stubs instead (where it's possible) - so, instead of adding your global karma installation as a library, download the karma-jasmine library from http/github.com/borisyankov/DefinitelyTyped:
-in Settings/JavaScript/Librariues, press Download...
-choose 'Typescript community stubs' from the dropdown
-select 'karma-jasmine' in a stubs list

Community stubs are light-weight as compared with node_modules and provide WebStorm with information about actual types, etc., making static analysis more accurate

0

Please sign in to leave a comment.