I am trying to deploy my app for the first time and running into problems with the asset pipeline. When I run bundle exec rake assets:precompile I get the following error;
cool_app@ip-10-248-17-168:/rails_apps/cool_app/current$ bundle exec rake assets:precompile
/home/cool_app/.rvm/rubies/ruby-1.9.3-p327/bin/ruby /rails_apps/cool_app/shared/bundle/ruby/1.9.1/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
Unexpected character '' (line: 13934, col: 1, pos: 403510)
Error
at new JS_Parse_Error (<eval>:1720:22)
at js_error (<eval>:1728:15)
at parse_error (<eval>:1824:17)
at next_token (<eval>:2070:17)
at handle_slash (<eval>:2024:32)
at Object.next_token [as input] (<eval>:2067:39)
at next (<eval>:2175:37)
at Object.semicolon [as 1] (<eval>:2221:38)
at prog1 (<eval>:2770:28)
at simple_statement (<eval>:2362:35)
(in /rails_apps/cool_app/releases/20121128034720/app/assets/javascripts/application.js)
I presume that this means I have an illegal character (that’s not rendering) somewhere in my maze of javascript (should have deployed earlier!) but telling me it’s at column 1 on line 13934 doesn’t seem to be particularly useful. How do I go about hunting this down? The error message is spectacularly unhelpful (and I notice a lot of other questions on this theme here too).
- Edit –
I’m not sure of the significance, but if I run RAILS_ENV=development rake assets:precompile on my development machine, the task seems to execute without complaint. My Server is Ubuntu 12.04 and my dev machine in OSX 10.8. I don’t know enough about Javascript runtimes to solve this myself right now (but I’m hunting).
Hokay,
My head hurts from the hours of bashing it against my keyboard but I solved my problem.
First, some reading around suggested that uglifier was the cause of my error. I set
config.assets.compress = falsein config/production.rb and sure enough I was able to precompile my assets.I wasn’t happy with this though as my Javascript file was 625kB and I really wanted it compressed, so I looked in the generated application.js file and found what line 13934, column 1 referred to. Turns out it was line 8, column 1 of the file jquery.caret.1.02.js, a small jQuery plugin I am using. This first line looks like so;
with a space in front of the line. I deleted that space (I suspect it is some incorrect non-printing unicode character but haven’t bothered looking into it), set
config.assets.compress = true, and tried again and no more error message! (and my Javascript is down to 159kB)I hope that this helps someone one day.