最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Node.js - Globally installed module showing 'MODULE_NOT_FOUND' - Stack Overflow

programmeradmin3浏览0评论

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 ment 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.

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 ment 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.

Share Improve this question asked Sep 5, 2015 at 14:43 JQuery MobileJQuery Mobile 6,30124 gold badges88 silver badges138 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 5

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

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/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.)

You need it locally for your app, run npm install webdriverio in the root directory of your app.

Node looks for modules in the innode_modules folders only (starting with current folder and then looking in the folder above). In order to make it work, you have to install this package locally as well.

npm install webdriverio

You can use the full global path:

const wdio = require('/usr/local/lib/node_modules/webdriverio');
发布评论

评论列表(0)

  1. 暂无评论