48

I'm trying to precompile my assets for production, but rails doesn't seem to be cooperating.

$ bundle exec rake assets:precompile
/home/drderp/.rvm/rubies/ruby-1.9.3-p194/bin/ruby /home/drderp/.rvm/gems/ruby-1.9.3-p194@global/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
Unexpected token punc, expected punc (line: 213, col: 13, pos: 5986)

Error
    at new JS_Parse_Error (<eval>:1720:22)
    at js_error (<eval>:1728:15)
    at croak (<eval>:2189:17)
    at token_error (<eval>:2196:17)
    at expect_token (<eval>:2209:17)
    at Object.expect (<eval>:2212:40)
    at Object.1 (<eval>:2763:38)
    at prog1 (<eval>:2770:28)
    at <eval>:2560:51
    at maybe_unary (<eval>:2665:27)
  (in /home/drderp/projects/p/app/assets/javascripts/application.js)

Tasks: TOP => assets:precompile:primary
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/home/drderp/.rvm/rubies/ruby-1.9.3-p194/b...]

Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

This is the entire contents of application.js:

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// Since javascript, no matter what order you load it in, executes in different order, it doesn't
// matter
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery

Rails version 3.2.8, running on Ruby 1.9.3.

edit:

Here's bundle exec rake assets:precompile --trace, as requested:

$ bundle exec rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/home/drderp/.rvm/rubies/ruby-1.9.3-p194/bin/ruby /home/drderp/.rvm/gems/ruby-1.9.3-p194@global/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
Unexpected token punc, expected punc (line: 213, col: 13, pos: 5986)

Error
    at new JS_Parse_Error (<eval>:1720:22)
    at js_error (<eval>:1728:15)
    at croak (<eval>:2189:17)
    at token_error (<eval>:2196:17)
    at expect_token (<eval>:2209:17)
    at Object.expect (<eval>:2212:40)
    at Object.1 (<eval>:2763:38)
    at prog1 (<eval>:2770:28)
    at <eval>:2560:51
    at maybe_unary (<eval>:2665:27)
  (in /home/drderp/projects/p/app/assets/javascripts/application.js)
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/ruby_racer_runtime.rb:34:in `rescue in block in eval'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/ruby_racer_runtime.rb:28:in `block in eval'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/ruby_racer_runtime.rb:80:in `block in lock'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/therubyracer-0.10.2/lib/v8/c/locker.rb:13:in `Locker'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/ruby_racer_runtime.rb:78:in `lock'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/ruby_racer_runtime.rb:27:in `eval'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/ruby_racer_runtime.rb:19:in `exec'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/uglifier-1.3.0/lib/uglifier.rb:100:in `compile'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/sprockets/compressors.rb:74:in `compress'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/processing.rb:265:in `block in js_compressor='
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/processor.rb:29:in `call'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/processor.rb:29:in `evaluate'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/tilt-1.3.3/lib/tilt/template.rb:76:in `render'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/context.rb:177:in `block in evaluate'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/context.rb:174:in `each'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/context.rb:174:in `evaluate'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/bundled_asset.rb:26:in `initialize'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/base.rb:244:in `new'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/base.rb:244:in `build_asset'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/index.rb:89:in `block in build_asset'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/caching.rb:19:in `cache_asset'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/index.rb:88:in `build_asset'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/base.rb:163:in `find_asset'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/index.rb:56:in `find_asset'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/sprockets/static_compiler.rb:23:in `block in compile'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/base.rb:212:in `block in each_logical_path'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/base.rb:200:in `block (2 levels) in each_file'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/base.rb:190:in `each'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/base.rb:190:in `each_entry'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/base.rb:198:in `block in each_file'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/base.rb:197:in `each'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/base.rb:197:in `each_file'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/sprockets-2.1.3/lib/sprockets/base.rb:210:in `each_logical_path'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/sprockets/static_compiler.rb:18:in `compile'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/sprockets/assets.rake:56:in `internal_precompile'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/sprockets/assets.rake:70:in `block (3 levels) in <top (required)>'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/home/drderp/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/sprockets/assets.rake:60:in `block (3 levels) in <top (required)>'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/home/drderp/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/bin/rake:19:in `load'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/bin/rake:19:in `<main>'
Tasks: TOP => assets:precompile:primary
rake aborted!
Command failed with status (1): [/home/drderp/.rvm/rubies/ruby-1.9.3-p194/b...]
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/file_utils.rb:53:in `block in create_shell_runner'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/file_utils.rb:45:in `call'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/file_utils.rb:45:in `sh'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/file_utils_ext.rb:39:in `sh'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/file_utils.rb:80:in `ruby'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/file_utils_ext.rb:39:in `ruby'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/sprockets/assets.rake:12:in `ruby_rake_task'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/sprockets/assets.rake:21:in `invoke_or_reboot_rake_task'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/home/drderp/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/bin/rake:19:in `load'
/home/drderp/.rvm/gems/ruby-1.9.3-p194@global/bin/rake:19:in `<main>'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `eval'
/home/drderp/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => assets:precompile
fredmaggiowski
  • 2,232
  • 3
  • 25
  • 44
Jeremy Rodi
  • 2,485
  • 2
  • 21
  • 40
  • Try running as bundle exec rake assets:precompile --trace ... it might help uncover a file with bad punctuation somewhere – rossta Sep 25 '12 at 01:27
  • @rossta, updated the OP with the output of the command. – Jeremy Rodi Sep 25 '12 at 01:31
  • What version of jquery-rails is in your Gemfile? – rossta Sep 25 '12 at 01:46
  • 4
    There is a syntax error somewhere in your javascript files. Try removing/adding jquery and/or any other lines in application.js (or other js files that might be getting included) and rerunning compilation to see if you can isolate the problem. – rossta Sep 25 '12 at 01:58
  • @rossta the entire contents of my application.js file is shown above, and when I remove the `require jquery`, it doesn't complain. No other files are being required. – Jeremy Rodi Sep 25 '12 at 12:16
  • @rossta `jquery-rails` is version 2.1.2 – Jeremy Rodi Sep 25 '12 at 12:17
  • 1
    I have this problem as well. Is there some way to tell which file is producing the error? – MrTheWalrus Apr 01 '13 at 20:00
  • @MrTheWalrus in `application.js`, remove `require`s until the error disappears, I guess? – Jeremy Rodi Apr 02 '13 at 13:05
  • In my case it was tagsinput.js , i had to remove from the assets folder and manually copy to the public folder, then add a – damuz91 May 27 '14 at 18:30

10 Answers10

145

A more universal way to find the problem in js-assets: Run rails console and:

JS_PATH = "app/assets/javascripts/**/*.js"; 
Dir[JS_PATH].each do |file_name|
  puts "\n#{file_name}"
  puts Uglifier.compile(File.read(file_name))
end
Sergey Reutskiy
  • 2,781
  • 2
  • 18
  • 14
  • 4
    `JS_PATH = 'app/assets/javascripts/**/*.js' ` `Dir[JS_PATH].each do |file|` `begin' `Uglifier.compile(File.read(file))` `rescue` `puts file` `end` Easier to read if you have lots of js files – Dania_es Aug 30 '16 at 18:12
  • 4
    changing the first line to `JS_PATH = "app/assets/javascripts/**/*.js*"` will include .js.erb files and the like – Erica Tripp Feb 04 '17 at 07:54
  • 6
    @erica That's not necessarily a great idea, since `Uglifier.compile` expects pure javascript, whereas `.js.erb` files may have embedded ruby in them. – Jeremy Rodi Apr 05 '17 at 20:55
  • 4
    I ended up having to do this multiple times, so I made a one-liner: `RAILS_ENV=whatever bundle exec rails runner 'Dir["app/assets/javascripts/**/*.js"].each {|file_name| puts "\n#{file_name}"; puts Uglifier.compile(File.read(file_name)) }'` – Nathan Wallace May 18 '17 at 20:23
  • 1
    Good to know @jeremy. It worked in my instance, but it's helpful to know that's it's not a failsafe solution. – Erica Tripp Jun 17 '17 at 08:06
  • Brutal... anyway to figure out which line an uglifier error is happening on if it's an erb file? – Meekohi Jul 02 '18 at 15:39
  • For anyone unable to identify the EXACT line(s) causing the issue in the file(s) shown via Sergey's solution, try https://www.jslint.com/ and https://eslint.org/demo/. I first cleaned up my code using the former, and finally identified the issue causing `RAILS_ENV=production rake assets:precompile` to break via the latter. – CFitz Mar 22 '19 at 02:37
  • It is just breaking in normal JS string interpolation. I guess i need to load and tell it about babel config or something. – Zia Ul Rehman Mughal Jan 23 '20 at 11:49
  • as a one-liner: `JS_PATH = "app/assets/javascripts/**/*.js"; Dir[JS_PATH].each{ |file_name| puts "\n#{file_name}"; puts Uglifier.compile(File.read(file_name)) }` – Aryeh Beitz Apr 02 '20 at 09:15
18

I had this same problem. Open your Javascript console in the browser and see where there is an error. I suspect (because it was the solution to my problem), that one of your JS files has an error and it is most likely whatever JS you wrote that used a ">" symbol.

Good luck error hunting.

Joseph Gill
  • 1,067
  • 11
  • 18
  • 2
    Bless you. My case was that I had a dynamic .js.erb file. On compiling the assets, the javascript was interpreted as if there were no `ENV['bla_bla']` giving a syntax error. :) – anonymous Oct 13 '14 at 14:40
  • 1
    In my case it was a file under `app/assets/javascripts` in a gem that didn't have an extension. – mooreds Apr 07 '16 at 18:48
13

In my case, I was using es6 syntax ()=>{...} in js file. Replacing it with function(){...} fixed the problem.

Ryo
  • 2,003
  • 4
  • 27
  • 42
  • 2
    This was the problem for me. Seems like Uglifier chokes on ES6 syntax. – Daniel Bonnell Jun 13 '16 at 12:46
  • I had a similar issue, I used a default value `function(options = {})`, seems I've been coding in ES6 too long ;) – Andrew K Feb 12 '17 at 00:49
  • This was exactly my case and I still wanted to use ES6 syntax. I ended up using `react_on_rails` (not for React, just to use Webpack to keep enjoying ES2015+) – elquimista Aug 19 '17 at 02:22
10

This was horrible; no javascript error on my local computer means that there's an issue with asset compilation.

Here's how I solved it.

As suggested in the comments for a similar question ExecJS::ProgramError: Unexpected token punc «(», expected punc «:» when running rake assets:precompile on production , I removed uglifier (in production.rb, comment out the compressor line) and compression altogether. (I had tried with other compressors; yui did not give much information. closure seemed to give me a hint but didn't help much)

I then compressed the assets locally, then I pushed to production. (To compress locally, use RAILS_ENV=production rake assets:precompile )

I ran on the server and this is when the javascript errors surfaced. It was basically erroneous merging of files (mainly due to something commented out). I got rid of those lines and pushed back to production. Everything succeeded.

I brought back uglifier, deleted the precompiled assets under public/assets/ and pushed back to production.

I hope this helps someone!

Community
  • 1
  • 1
Abdo
  • 13,549
  • 10
  • 79
  • 98
2

Just a heads up on this, I had same issue and what was happening, when precompiling assets in production environment (and pushing to Heroku) several of my JS files were being inserted with foreign characters, along the lines of...

<<<<<<<<HEAD

===========

>>>>>>(random alphanumeric key)

I just ran a global search in my site directory for "<<" and quickly found the affected files & deleted these terms - everything worked fine.

  • 1
    This is actually what happens when git performs a merge. You may have accidentally started a merge when pulling down a branch, and then didn't clean up the results of the merge. See [this](http://git-scm.com/docs/git-merge) (scroll down to "How Conflicts are Presented"). – Jeremy Rodi Jan 11 '15 at 17:27
2

For some reason, on Heroku and also when I ran the above-mentioned code to "uglify" the javascript in the rails console, it would not report the line number of the error!. It is just a ruby wrapper for UglifyJS, which you can use online here https://skalman.github.io/UglifyJS-online/.

So I just copied and pasted the offending js file in here, and it reported the line number. Very easy.

Ibraheem Zafar
  • 346
  • 1
  • 9
salza80
  • 21
  • 2
2

Necessary details:

For us, it was a weird little thing which leads us to actual underlying error, hence solution.

We had uglifier gem v 4.1.x and latest at the time of writing is 4.2.x we updated the uglifier version, just in case.

And what happened was that this new version actually started spitting out actual file locations where the error of compilation was happening. And when we know where the error is coming from, we fix it.

Additional details:

The actual issue was that we had some js.erb files and these files were running some rails code to populate some env data, something like:

const config = {
  abc: <%= Figaro.env.abc %>,
  xyz: <%= Figaro.env.xyz %>
}

And the error we were getting was: Uglifier::Error: Unexpected token: punc (,).

So it was obvious for some reason Figaro was not giving us our desired values. We went on to fix that and checked our assumption by hardcoding random values, which compiled the JS successfully.

Putting it here so it may help someone.

PS: Top answer is great, but for some reason, it gave us some random jsx related errors to us instead of giving us an actual error.

Ibraheem Zafar
  • 346
  • 1
  • 9
Zia Ul Rehman Mughal
  • 2,119
  • 24
  • 44
1

Verify the new JS files that you added in your application include plugins and other added by Bower or something like it.

Try add one by one to find what file have problem. In my case was in anchor-scroll.js. When I changed to use anchor-scroll.min rake runs ok.

Change this:

//= require anchor-scroll/scroll

For:

//= require anchor-scroll/scroll.min
monteirobrena
  • 2,562
  • 1
  • 33
  • 45
1

My problem was with two success calls.

First was mqtt onSuccess:

onSuccess() {
  console.log("mqtt connected")
};

that I solved with:

onSuccess: function() {
  console.log("mqtt connected")
};

and the second was Ajax success. Linter will show you

Error: Expected method shorthand

but everything will work properly.

fredmaggiowski
  • 2,232
  • 3
  • 25
  • 44
Radovan Skendzic
  • 2,923
  • 1
  • 14
  • 22
-4

"/home/drderp/.rvm/rubies/ruby-1.9.3-p194/bin/ruby /home/drderp/.rvm/gems/ruby-1.9.3-p194@global/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets"

There's a space between the bolded portion (between ruby, the backslash, and home).

I don't know if this was a typo, but it could be your problem because Rails doesn't like spaces in directory names. Rename that folder, and try running your code again.

New Alexandria
  • 6,951
  • 4
  • 57
  • 77
skmichaelson
  • 450
  • 5
  • 7
  • 4
    There should be a space; its not in the filename, I'm running the ruby executable, with the absolute path to the rake file. – Jeremy Rodi Oct 10 '13 at 18:07