[英]Cannot find module within another function/file
I'm running a casper project and I have two files: 我正在运行一个casper项目,我有两个文件:
The code in main.js
is: main.js
的代码是:
var casper = require('casper').create();
var aSecondary = require('./secondary.js');
aSecondary.secondaryRun();
The code in secondary.js
is: secondary.js
的代码是:
function secondaryRun() {
var aSecondaryCasper = require('casper').create();
}
exports.secondaryRun = secondaryRun;
Error: Cannot find module 'casper' /home/username/phantomjs:/platform/secondary.js:1 in secondaryRun 错误:在secondaryRun中找不到模块'casper'/home/username/phantomjs:/platform/secondary.js:1
I don't understand why I can find the casper module in main.js
and not in secondary.js
. 我不明白为什么我可以在main.js
而不是secondary.js
找到casper模块。
Thanks 谢谢
Fixed this. 解决此问题。 It's documented at: http://docs.casperjs.org/en/latest/writing_modules.html 记录在: http : //docs.casperjs.org/en/latest/writing_modules.html
I required this in secondary.js to get it working: 我需要在secondary.js中使其正常工作:
var require = patchRequire(require);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.