Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何要求来自另一个模块的模块-Nodejs_Javascript_Node.js_Express_Npm_Phantomjs - Fatal编程技术网

Javascript 如何要求来自另一个模块的模块-Nodejs

Javascript 如何要求来自另一个模块的模块-Nodejs,javascript,node.js,express,npm,phantomjs,Javascript,Node.js,Express,Npm,Phantomjs,我有我的nodejs应用程序,它由两个文件组成,index.js是主文件,能够路由和所有其他东西,ping.js是使用phantomJS功能的。在我的index.js中,我有以下调用: var phantomMy = require('./ping.js'); 在ping.js中,我需要phantomJS-webpage的标准模块,所以我有这样的调用 var page = require('webpage').create(); 但这给了我一个错误: Error: Cannot find m

我有我的nodejs应用程序,它由两个文件组成,index.js是主文件,能够路由和所有其他东西,ping.js是使用phantomJS功能的。在我的index.js中,我有以下调用:

var phantomMy = require('./ping.js');
在ping.js中,我需要phantomJS-webpage的标准模块,所以我有这样的调用

var page = require('webpage').create();
但这给了我一个错误:

Error: Cannot find module 'webpage'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    ..

我做错了什么?也许不仅仅是从语法角度,而且从架构角度来看?

网页模块是PhantomJS的一个模块。如果使用node index.js运行该文件,则会出现该错误。您需要将其作为phantomjs index.js运行,它才能工作。如果您试图与phantomjs进行通信,我建议您研究其他模块,例如,而不是编写自己的模块。

可能的重复向我们展示网页结构。我在npmjs上找不到模块网页。可能出现两个问题:1/。requirepathTofile 2/中的目标错误。网页的结构不正确。必须是return module.exports=函数{}