Webstorm not seeing global npm packages

My laptop runs on macOS Sierra and I intalled node.js with brew. I installed all npm packages with -g global flag. Currently when I run `which node` I get:

`/usr/local/bin/node`. The npm modules themselves are installed in this directory: usr/local/lib/node_modules

When I use `require("xmlhttprequest");` and use `xmlhttprequest` specific function I get TypeError which says that the function is not recognized. I made sure that Node.js Core library is enabled. Also in the screenshot you can see the package `xmlhttprequest`.

 

I tried many things to fix the problem: 

1) reinstalled node

2)added NODE_PATH variable to point to `which node`. 

3) tried opening webstorm from terminal as described in this thread: https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000087690-How-to-set-location-of-global-NPM-modules-in-WebStorm-

 

The only way I managed this to get working is to install the same package from webstorm prompt "Module not listed in package.json dependencies" (pressing opt + return) and then manually creating package json file in the project folder and manually specified the dependencies which is not a healthy workaround.

I tried many things to make it work: r

0
3 comments

Node.js normally doesn't support requiring globally installed modules. And it's strongly recommended to have all modules required by your application installed locally, in project node_modules.

You can, however, use NODE_PATH environment variable to specify your modules location

See https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders

0

Thank you! Now I understand that for projects I need to install packages locally. So I created a package.json file and then ran npm install which installed the package and creates node_modules directory. However, Webstorm still doesn't recognize the functions of the package. Can you please point me in the right direction?


0

It's not WebStorm, the error is thrown by Node.js. It's likely a problem with your code. See https://stackoverflow.com/questions/49201192/type-error-xmlhttp-is-not-a-constructor for some hints

1

Please sign in to leave a comment.