Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js - Globally installed module showing 'MODULE_NOT_FOUND'

I am using Node.js for a project. I installed WebdriverIO globally using

npm install -g webdriverio

In one of my files, I have:

file.js

var webdriverio = require('webdriverio');

When this file gets loaded, I get an error in the console that says:

Message:
    Cannot find module 'webdriverio'
Details:
    code: MODULE_NOT_FOUND

If I comment out the line var webdriverio = ..., my code runs fine.

Considering I've installed webdriverio globally, I do not understand why I'm getting this problem.

like image 546
JQuery Mobile Avatar asked Dec 09 '22 01:12

JQuery Mobile


2 Answers

Node.js require looks into the local node_modules folder.

Check this link to learn how to load modules from the global modules folder:

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

If the NODE_PATH environment variable is set to a colon-delimited list of absolute paths, then node will search those paths for modules if they are not found elsewhere. (Note: On Windows, NODE_PATH is delimited by semicolons instead of colons.)

like image 28
Catalin MUNTEANU Avatar answered Dec 11 '22 09:12

Catalin MUNTEANU


When you install globally, you should then go to the root of your app and call:

npm link webdriverio

P.S. no need to call npm install, since you will end up having two separate installations of this module, one in global and another in your local node_modules folder

like image 135
subzero10 Avatar answered Dec 11 '22 11:12

subzero10