-1

So very suddenly on a production server running ruby 2.1.2p95 and rails 3.2.14, I've started getting an error from what looks like underscore.js. This is only on this server.

Uncaught SyntaxError: Unexpected token ILLEGAL

b/c this is production the code is minified but using chrome to expand it this is where it is saying the issue is:

S.template = function(e, t, n) {
    var i;
    n = S.defaults({}, n, S.templateSettings);
    var r = new RegExp([(n.escape || L).source, (n.interpolate || L).source, (n.evaluate || L).source].join("|") + "|$", "g"), s = 0, a = "__p+='";
    e.replace(r, function(t, n, i, r, o) {
        return a += e.slice(s, o).replace(O, function(e) {
            return "\\" + P[e]
        }), n && (a += "'+\n((__t=(" + n + "))==null?'':_.escape(__t))+\n'"), i && (a += "'+\n((__t=(" + i + "))==null?'':__t)+\n'"), r && (a += "';\n" + r + "\n__p+='"), s = o + t.length, t
    }), a += "';\n", n.variable || (a = "with(obj||{}){\n" + a + "}\n"), a = "var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n" + a + "return __p;\n";
    try {
        i = new Function(n.variable || "obj", "_", a) // <---- right here --<<
    } catch (o) {
        throw o.source = a, o
    }
    if (t)
        return i(t, S);
    var l = function(e) {
        return i.call(this, e, S)
    };
    return l.source = "function(" + (n.variable || "obj") + "){\n" + a + "}", l
}

Now obviously I have not touched the underscore.js code itself and I have tried downloading the most current version of underscore.js and still get the same thing.

Just to see if I could reproduce the error on my local machine I set the project to production and rake assets:precompile and I still do not get the error locally.

My guess is that this is something to do with my Gem versions or the actual environment on my server but I've been debugging these things for a while now and see no change at all.

Gemfile: (w/o unrelated gems)

gem 'rails', '3.2.14'
gem 'json'

group :assets do
  gem 'sprockets'
  gem 'sass-rails'
  gem 'coffee-rails'
  gem 'uglifier'
  gem 'haml_coffee_assets', '1.8.2'
  gem 'execjs'#, '1.4.0'
  gem 'therubyracer'#, '0.10.2', :require => 'v8'
  gem 'momentjs-rails'
end

# javascript gems
gem 'jquery-rails', '2.1.4'

Any help would be greatly appreciated, thanks

Sparkmasterflex
  • 1,837
  • 1
  • 20
  • 33
  • The error has to do with the argument being passed as a parameter to the Function constructor. Knowing the value of that is the key to figuring out what's going on (or at least to getting started). – Pointy Aug 21 '14 at 19:14
  • And it looks like the problem stems from a bug in a template, so check to see what template files have changed lately. – Pointy Aug 21 '14 at 19:16
  • possible duplicate of [SyntaxError: Unexpected token ILLEGAL](http://stackoverflow.com/questions/12719859/syntaxerror-unexpected-token-illegal) – Brad Werth Aug 21 '14 at 19:41
  • No nothing in my template code has changed recently. And it's on every single page that uses Backbone/Underscore. Again this only occurs on our production server and started just a couple days ago after a deploy. – Sparkmasterflex Aug 22 '14 at 12:21

1 Answers1

0

Ok...

I found the problem. It was something I did with the JavaScript but had nothing to do with the JS code that was breaking.

A bit ago I was debugging in IE and discovered that d3.js doesn't support IE7 and IE8 so after some searching I found a library to correct this. r2d3.js

I added this and another bit of code to correct another issue with IE in relation to this. (I'm sorry, but I for get the exact issue, probably what I'm seeing now). Later I realized that the way that I was including these was including them in the standard JS for all non-IE browsers. So I moved them out of the assets pipeline and tried to include them that way.

I have no idea why it is breaking this way, but I just reverted it to be included as before (within the assets pipeline) and the error no longer appears.

Anyone with tips on how I can include these JS files for IE only I would love to hear them.

Sparkmasterflex
  • 1,837
  • 1
  • 20
  • 33