12

I'm having trouble getting Iron Router and Spiderable working together nicely in my Meteor.js app. If I test a url with ?_escaped_fragment_= whilst running on my localhost it all works correctly but as soon as i push to our DigitalOcean production server i keep getting the following error when trying the same thing (check out http://hreglobal.com/?_escaped_fragment_=):

Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
at Object.Meteor._nodeCodeMustBeInFiber (packages/meteor/dynamics_nodejs.js:9)
at _.extend.get (packages/meteor/dynamics_nodejs.js:21)
at RouteController.lookupOption (packages/iron:router/lib/route_controller.js:66)
at new Controller.extend.constructor (packages/iron:router/lib/route_controller.js:26)
at ctor (packages/iron:core/lib/iron_core.js:88)
at Function.Route.createController (packages/iron:router/lib/route.js:133)
at Function.Router.createController (packages/iron:router/lib/router.js:185)
at Function.Router.dispatch (packages/iron:router/lib/router_server.js:39)
at Object.router (packages/iron:router/lib/router.js:15)
at next (/opt/hre/bundle/programs/server/npm/webapp/node_modules/connect/lib/proto.js:190:15)

Have been trying to find the cause for days now and starting to get a bit desperate. Any pointers welcome!

Rik Nauta
  • 229
  • 2
  • 7

3 Answers3

2

There are a few causes for this:

When this happens on production but not locally this could mean a package has a minification problem. To test this you can run meteor build --debug which skips minification and deploy. Or you can run locally with meteor run --production which will run it locally with minification. Either way should show you if it's a minification problem.

Another option for production issues but not local issues is a timeout issue with spiderable. It may be worth increasing the timeout to see if that solves the problem. I would try the minification first though.

The third production issue but not local issue has to do with the ROOT_URL being wrong. This is also worth checking quickly. Make sure that the ROOT_URL that your server is configured to use is accessible by the server itself.

If this is happening both locally and on a production server, that can be caused by publish calls that do not properly return ready(). This can be debugged by commenting out subscriptions on the faulty endpoint until you find the faulty publish.

Tim C
  • 1,874
  • 12
  • 25
0

Is phantomjs installed/accessible to the script on the remote host?

I installed a more sophisticated spiderable package:

https://atmospherejs.com/jazeee/spiderable-longer-timeout

that showed me an actual error message instead of irrelevant Error: Meteor code must always run within a Fiber.

The error code appeared to be:

spiderable: phantomjs not installed. Download and install from http://phantomjs.org/

Things started to work immediately after:

sudo apt-get install phantomjs

romaroma
  • 638
  • 8
  • 13
0

Jut in case this helps anyone in the future...

I was experiencing this issue as well. I tried everything I could think of and everything all other forums suggested.

The fix for me was my server! I have a t2.nano with AWS EC2 and I had uploaded my apps with mup.

It took me a long time to realise this was the cause... but if I just have 2 apps running everything works ok. I then added a third app and this is when problems occurred. I'm guessing it is down to the basic server I was running not being able to handle 3 docker containers for my apps and a fourth for mongo.

I always had issues uploading my third app with mup as well. I'm guessing this might be part of the issue.

So the point is... your publications etc might all be ok but the time to get a response from the server itself rather than the app can have an affect on this too.