Javascript 流星噩梦引发异常
我安装了梦魇 npm安装噩梦——保存在我的meteor项目中。 然后,我尝试在模板助手方法中运行噩梦示例代码:Javascript 流星噩梦引发异常,javascript,node.js,exception,meteor,nightmare,Javascript,Node.js,Exception,Meteor,Nightmare,我安装了梦魇 npm安装噩梦——保存在我的meteor项目中。 然后,我尝试在模板助手方法中运行噩梦示例代码: Template.nighmare.events({ "click #doSomething"() { let Nightmare = require('nightmare'); let nightmare = Nightmare({ show: true }); nightmare .goto('https://duckduckgo.com
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)
未捕获类型错误:fs.existsSync不是函数
在meteoinstall.node_modules.electron.index.js(modules.js?hash=1ae810a…:109967)
在fileEvaluate(modules runtime.js?hash=0969a31…:207)
在需要时(modules runtime.js?hash=0969a31…:130)
在meteoinstall.node_modules.monda梦.lib.monda梦.js(modules.js?hash=1ae810a…:107767)
在fileEvaluate(modules runtime.js?hash=0969a31…:207)
在需要时(modules runtime.js?hash=0969a31…:130)
在Object.click上点击#doSomething(app.js:4330)
在blaze.js?hash=813922c…:3774
在Function.Template.withTemplateInstanceFunc(blaze.js?hash=813922c…:3743)
在Blaze.View。(blaze.js?hash=813922c…:3773)
我不知道如何解决这个问题,任何提示或暗示都将不胜感激
有人让meteor+噩梦一起工作吗
如果我将相同的代码放在test.js文件中,并在其自己的项目中与node test.js一起运行,效果会很好。应该在node上运行,而不是直接在浏览器中运行
模板.Template\u name.events中的代码在客户端浏览器上执行,因此会显示错误消息
您可能会尝试通过将噩梦代码移动到仅限服务器的方法中,并在事件处理程序中调用该方法来实现所要做的事情