【发布时间】:2017-05-18 12:29:46
【问题描述】:
我安装了噩梦 npm install nightmare --save 在我的流星项目中。 然后我尝试在模板辅助方法中运行噩梦示例代码:
Template.nighmare.events({
"click #doSomething"() {
let Nightmare = require('nightmare');
let nightmare = Nightmare({ show: true });
nightmare
.goto('https://duckduckgo.com')
.type('#search_form_input_homepage', 'github nightmare')
.click('#search_button_homepage')
.wait('#zero_click_wrapper .c-info__title a')
.evaluate(function () {
return document.querySelector('#zero_click_wrapper .c-info__title a').href;
})
.end()
.then(function (result) {
console.log(result);
})
.catch(function (error) {
console.error('Search failed:', error);
});
}
})
当从(我单击一个按钮)调用此代码时,我得到了异常:
Uncaught TypeError: fs.existsSync is not a function
at meteorInstall.node_modules.electron.index.js (modules.js?hash=1ae810a…:109967)
at fileEvaluate (modules-runtime.js?hash=0969a31…:207)
at require (modules-runtime.js?hash=0969a31…:130)
at meteorInstall.node_modules.nightmare.lib.nightmare.js (modules.js?hash=1ae810a…:107767)
at fileEvaluate (modules-runtime.js?hash=0969a31…:207)
at require (modules-runtime.js?hash=0969a31…:130)
at Object.click #doSomething (app.js:4330)
at blaze.js?hash=813922c…:3774
at Function.Template._withTemplateInstanceFunc (blaze.js?hash=813922c…:3743)
at Blaze.View.<anonymous> (blaze.js?hash=813922c…:3773)
我不知道如何解决这个问题,任何提示或提示将不胜感激!
有谁让流星+噩梦一起工作?
如果我将相同的代码放在 test.js 文件中并在其自己的项目中使用节点 test.js 运行它就可以了。
【问题讨论】:
标签: javascript node.js exception meteor nightmare