【问题标题】:Cannot find module within another function/file在另一个函数/文件中找不到模块
【发布时间】:2018-10-26 07:52:09
【问题描述】:

我正在运行一个 casper 项目,我有两个文件:

main.js中的代码是:

var casper = require('casper').create();
var aSecondary = require('./secondary.js');
aSecondary.secondaryRun();

secondary.js中的代码是:

function secondaryRun() {
    var aSecondaryCasper = require('casper').create();
}
exports.secondaryRun = secondaryRun;

错误:找不到模块“casper” /home/username/phantomjs:/platform/secondary.js:1 在secondaryRun

我不明白为什么我可以在 main.js 而不是 secondary.js 中找到 casper 模块。

谢谢

【问题讨论】:

    标签: javascript module phantomjs casperjs


    【解决方案1】:

    解决了这个问题。它记录在:http://docs.casperjs.org/en/latest/writing_modules.html

    我需要在 secondary.js 中使用它才能使其正常工作:

    var require = patchRequire(require);
    

    【讨论】:

      猜你喜欢
      • 2021-03-10
      • 1970-01-01
      • 2017-03-16
      • 2022-06-10
      • 1970-01-01
      • 1970-01-01
      • 2021-07-09
      • 2021-04-19
      • 2016-07-08
      相关资源
      最近更新 更多