Reputation: 32130
I am deploying to heroku yet I saw that the css files aren't being served (they also cannot be found on heroku).
I read that I need to do rake assets:precompile locally at first yet when I do it I get:
C:\project>bundle exec rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
rake aborted!
undefined: Unexpected token: operator (<)
(in C:/project/app/assets/javascripts/application.js)
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
I have nothing in application.js so I don't understand where the error is..
application.js is
// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require_tree .
Thank you
Update
If removing a .js.erb file I get the following error
C:\project>bundle exec rake assets:precompile RAILS_ENV=production --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
rake aborted!
706: unexpected token at 'C:\Users\me\AppData\Local\Temp\execjs20111021-6448-ei2nm3.js(2, 3) Microsoft JScript runtime error: Out of memory
'
(in C:/project/app/assets/javascripts/application.js)
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
Still have problems with erb css and js files not compiling...
This doesn't seem to end.. Thanks
Upvotes: 7
Views: 7649
Reputation: 478
I was having the same issue and it turned out to be caused by the inclusion of a embed javascript which had comments in the format: <!-- comment -->
I've removed them and it worked like a charm! Hopefully this helps.
Upvotes: 3
Reputation: 21
I had a similar problem:
Unexpected token: operator (<<)
This turned out to be a left over file from a merge conflict in Git. The conflict leaves a .orig file that contains "<<<<<<<<<<" wherever Git finds a block of code to be merged.
Because of the asset pipeline directive
//= require_tree .
in application.js, all files in the javascript folder (including .orig files) get precompiled on a push to servers like Heroku. The precompiler finds fault with the "<<<<<".
So my solution was to find all the .orig files and delete them from Git, using the 'git rm filename' method.
Upvotes: 0
Reputation: 509
I have the same issue here! In my case, what causes this issue is that, I add a new JS file to javascript folder, and I got an undefined: Unexpected token: operator (<)
error while I tried to run precompile command. So I look into the new js file and found there is a HTML style comment <!-- -->
in that file. I remove it and life is good now!
So try to find out is there any HTML style comment <!-- -->
in your js file and just remove those comments. This is especially true when some JS code is copied from html file!
Upvotes: 5
Reputation: 6793
I've spent the last 1 hour scratching my head after encountering the same bug. The problem is the following line in your application.js:
//= require_tree .
This causes all files in your app/assets/javascripts/
directory to get included and it could be that there is some sort of bug in another file in the directory. I removed that line and got my assets to precompile (I wasn't really using application.js). So, look for a bug in a file being included by application.js
Upvotes: 1
Reputation: 21569
I think it is caused by an external javascript file which is not well-code-formatted. e.g.
function say_hi(){
// NOTICE that there's no semi-colon there!
name = "Jim"
alert("hi" + name )
}
when under the precompile, your code would put in 1 line, and since there's no necessary semicolon, your generated js file probably contains errors, like
"undefined: Unexpected token: operator (<)"
or something.
so, my suggestion is:
don't compress the js file if it's not well code-formatted, by setting "config.assets.compress = false" in your config file, following @Mike's answer.
use coffeescript as possible, it will help you generate very well formatted code. ( I am not a coffeescript guru, so please correct me if I am wrong )
Upvotes: 3
Reputation: 9842
I've been struggling with this trying to deploy to a staging server. The solution that works for me is to make sure you have the following in your config/environments/[your_environment].rb
file:
config.assets.compress = false
By default, the compressors aren't available in environment other than production, which is why the precompile was failing.
Upvotes: 5
Reputation: 33732
one thing I noticed is that it should be:
RAILS_ENV=production bundle exec rake assets:precompile
the definition of the RAILS_ENV needs to go before the bundle
command, because it's setting the shell (bash) environment variable for the shell that executes the bundle
command.
Your problems seems to be related to this:
https://github.com/bradphelan/jasminerice/issues/21
See also:
http://guides.rubyonrails.org/asset_pipeline.html
Heroku rails 3.1 app - compiling assets locally vs compiling assets during slug compilation
Error compiling Rails 3 CSS asset on Heroku
Upvotes: 1