iron-meteor / iron-router

A client and server side router designed specifically for Meteor.
MIT License
1.98k stars 412 forks source link

spiderable errors #1150

Open aldeed opened 9 years ago

aldeed commented 9 years ago

Seeing this error with every spiderable request using latest iron:router (1.0.6).

spiderable: phantomjs failed: null 
stderr: 
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:1)
    at [object Object]._.extend.get (packages/meteor/dynamics_nodejs.js:21:1)
    at [object Object].RouteController.lookupOption (packages/iron:router/lib/route_controller.js:66:1)
    at new Controller.extend.constructor (packages/iron:router/lib/route_controller.js:26:1)
    at [object Object].ctor (packages/iron:core/lib/iron_core.js:88:1)
    at Function.Router.createController (packages/iron:router/lib/router.js:201:1)
    at Function.Router.dispatch (packages/iron:router/lib/router_server.js:39:1)
    at Object.router (packages/iron:router/lib/router.js:15:1)
    at next (/mnt/data/2/node_modules/connect/lib/proto.js:190:15)
    at packages/spiderable/spiderable_server.js:123:1

Is it something in one of my router hooks? What's the best way to debug this?

joernroeder commented 9 years ago

same error here…

joernroeder commented 9 years ago

@aldeed did you find a fix for this issue?

aldeed commented 9 years ago

No. Removed spiderable for now.

timothyarmes commented 9 years ago

Spiderable was working on my local server. I've just uploaded to a digital ocean server using mup (with the option to install PhantomJS set to true) and I'm also seeing this error.

Can anyone help solve this?

marcelpanse commented 9 years ago

Same issue here..

dasmodel commented 9 years ago

Anyone figured this out yet? Or have a workaround?

marcelpanse commented 9 years ago

Eventually it didn't have much to do with iron router, but with some client-side javascript errors that crashed phantomjs, make sure there are no client-side javascript errors whatsoever.

dasmodel commented 9 years ago

Strange...no client-side errors for me at all but still the same issue!

dasmodel commented 9 years ago

Ok I found what I think was causing the issue for me — it looks like when I take away all my external <script> tags in my <head>, the error disappears. But that means I'm unable to load typekit, google analytics, etc. which is problematic...

fabien-h commented 9 years ago

I ran into the same problem and it drove me crazy. Removing the <script> tags in the header of my html solve the problem. I have typekit and ga too. You just have to add this in your app.js (or whatever fires first) :

( function ( i, s, o, g, r, a, m ) {console.log( arguments ); i[ 'GoogleAnalyticsObject' ] = r; i[ r ] = i[ r ] || function () {( i[ r ].q = i[ r ].q || [] ).push( arguments ); }, i[ r ].l = 1 * new Date(); a = s.createElement( o ), m = s.getElementsByTagName( o )[ 0 ]; a.async = 1; a.src = g; m.parentNode.insertBefore( a, m ); } )( window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga' );
ga( 'create', 'xxx', 'auto' );
ga( 'send', 'pageview' );

// Load the fonts
$.getScript( '//use.typekit.net/xxx.js', function () {
    try {
        Typekit.load();
    } catch ( e ) {}
} );
fabien-h commented 9 years ago

Well.. actually, it did not solved my problem. Back to crazy :(

Everything used to work perfectly fine until two weeks ago (the application is deployed on modulus, works fine in local)

dasmodel commented 9 years ago

@fabien-h I tried out your solution with several scripts moved from my <head> tag into my compatibility folder. It is now working with GA, heap analytics, and zopim, but Typekit seems to be the real issue here. Once I remove typekit, escaped fragment seems to work without any issues.

fabien-h commented 9 years ago

hum, that will be a problem...

Do you know how to check if the page is rendered by the client or by phantom js ?

thomasspiesser commented 9 years ago

seeing the same error. even when i remove everything from the <head> tag. earlier on an @import statement in my css caused the same error btw, but also on localhost with --production. the site is deployed on myApp.meteor.com. did anyone manage to solve the issue yet? on a side note, could this be related to the fiber issue #1192 ?

louis49 commented 8 years ago

Seems working on my config with iron:router@1.0.12

bshamblen commented 8 years ago

I'm running into the same issue. In my particular case I'm using both the spiderable package (for rendering the majority of the pages on my site to web crawlers), and the meteorhacks:ssr package in conjunction with the iron-router where: 'server' option (for rendering two specific routes that must be rendered on the server every time).

I followed the code back through the stack trace and it looks like an issue in the RouteController.lookupOption function. I believe the issue is that, for some reason, the CurrentOptions environmental variable is not set when the lookupOptions function is called. So, when the following line is executed, an error is thrown:

var opts = CurrentOptions.get();

I copied an pasted all of the code for the RouteController.prototype.lookupOption function into my project and wrapped the code that checks for the current options in an if statement to check to see if the CurrentOptions variable is undefined, and it no longer throws the fibers error.

// see if we have the CurrentOptions dynamic variable set.
if (typeof CurrentOptions !== 'undefined') {
    var opts = CurrentOptions.get();
    if (opts && _.has(opts, key))
        return opts[key];
}

I still get the following error at the cli, but the page renders:

spiderable: phantomjs failed at http://localhost:3000/ns: { [Error: Command failed: ] killed: true, code: 1, signal: null }