When using Phantom.js and the phantom
NPM package in Meteor.js, I'm getting an error stating that Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
I tried wrapping the findOne
function with Meteor.wrapAsync
and Phantom's callback functions with Meteor.bindEnvironment
but the error persists.
What can we do?
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:
Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.