gpt4 book ai didi

require - 将 require 与 casperjs 结合使用会返回 "Can' t find module"错误

转载 作者:行者123 更新时间:2023-12-04 17:10:21 34 4
gpt4 key购买 nike

我正在关注 writing a module with casperjs 上的文档,但我收到一个错误。

代码,直接来自文档:

// my module, stored in universe.js
// patching phantomjs' require()
var require = patchRequire(require);

// now you're ready to go
var utils = require('utils');
var magic = 42;
exports.answer = function() {
return utils.format("it's %d", magic);
};

和调用脚本:
var universe    = require("./universe");
var casper = require("casper").create();


console.log(universe.answer());

casper.test.begin("Home Page", 1, function suite(test) {

});

但我收到以下错误:
casperjs test testStage.js
Test file: testStage.js
CasperError: Can't find module ./universe
/usr/local/Cellar/casperjs/1/libexec/bin/bootstrap.js:214 in patchedRequire
/Users/smosk/Google Drive/source/nest/testStage.js:1
FAIL CasperError: Can't find module ./universe
# type: error
# file: testStage.js
# subject: false
# error: "CasperError: Can't find module ./universe"
# stack: in patchedRequire() in /usr/local/Cellar/casperjs/1/libexec/bin/bootstrap.js:214
in anonymous() in testStage.js:1
FAIL 1 test executed in 0.031s, 0 passed, 1 failed, 0 dubious, 0 skipped.

Details for the 1 failed test:

In testStage.js
Untitled suite in testStage.js
error: CasperError: Can't find module ./universe

还尝试先定义 casper:
var casper      = require("casper").create();
var universe = require("./universe");

但这只是导致
Test file: testStage.js
CasperError: Can't find module ./universe
/usr/local/Cellar/casperjs/1/libexec/bin/bootstrap.js:214 in patchedRequire
/Users/smosk/Google Drive/source/nest/testStage.js:2

最佳答案

您应该尝试升级到 CasperJS 的最新主版本,如下 pull request我所做的应该可以解决您遇到的问题。

但是,如果您不想升级,也可以尝试使用以下命令运行 C​​asperJS:

casperjs test ./testStage.js

关于require - 将 require 与 casperjs 结合使用会返回 "Can' t find module"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18347421/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com