将Phantom.js与Meteor.js一起使用时出错:Meteor代码必须始终在光纤内运行

时间:2015-03-05 20:15:28

标签: javascript node.js meteor phantomjs node-fibers

在Meteor.js中使用Phantom.js和phantom NPM包时,我收到错误消息,指出Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.

我尝试将findOne函数与Meteor.wrapAsync和Phantom的回调函数一起包裹Meteor.bindEnvironment,但错误仍然存​​在。

我们能做什么?

var phantom = Meteor.npmRequire('phantom')
phantom.create(Meteor.bindEnvironment( function (ph) {
  ph.createPage(function (page) {
    page.open('http://www.google.com', function (status) {

        console.log('Page Loaded');

        page.evaluate( function () { 
            return document.documentElement.outerHTML; 
        }, function (html) {

            // ERROR OCCURS HERE
            Animals.findOneAsync = Meteor.wrapAsync(Animals.findOne)
            var animals = Animals.findOneAsync({city:'boston'})

        });

        ph.exit();

    });
  });
}) );

错误:

Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.

0 个答案:

没有答案