[英]Error: Cannot find module 'utils'
I'm running a file main.js
using Casper.js via casperjs main.js
, which uses a module ./lib/myUtils.js
, which in turn uses 我正在通过
casperjs main.js
main.js
使用Casper.js运行main.js
文件,该文件使用模块./lib/myUtils.js
,而该模块又使用
var utils = require('utils')
But running casperjs main.js
throws the error 但是运行
casperjs main.js
会引发错误
Error: Cannot find module 'utils'
phantomjs://bootstrap.js:289
phantomjs://bootstrap.js:254 in require
/Users/username/casper-test/lib/myUtils.js:2
/Users/username/casper-test/lib/myUtils.js:63
TypeError: 'undefined' is not a function (evaluating 'myUtils.loadCookies()')
/Users/username/casper-test/main.js:104
The functions being imported have "use strict";
导入的功能具有
"use strict";
in their first line. 在他们的第一行。
However putting the code from myUtils.js
directly into main.js
avoids the error. 但是,将
myUtils.js
的代码直接放入main.js
可以避免该错误。 Why is this? 为什么是这样?
I suppose you need to insert var require = patchRequire(require);
我想您需要插入
var require = patchRequire(require);
at the beginning of your file ( myUtils.js
). 在文件的开头(
myUtils.js
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.