"rake assets: precompile" gives a punc error

I am trying to precompile my assets for production, but the rails do not seem to work.

$ 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 all the 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 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 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.

change

Here is 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 
+37
ruby ruby-on-rails ruby-on-rails-3 assets
Sep 25 '12 at 1:13
source share
9 answers

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 
+114
Jul 06 '16 at 16:14
source share
โ€” -

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

Searches for good luck mistakes.

+18
Nov 08 '13 at 0:13
source share

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

+11
Jan 27 '16 at 4:44
source share

It was terrible; no javascript error on my local computer means that there is a problem with asset compilation.

This is how I solved it.

As suggested in the comments on a similar question ExecJS :: ProgramError: Unexpected token punc "(", expected punc ":" when starting rake assets: precompile on production I deleted uglifier (in production.rb , commented out the compressor line) and generally compressed ( I tried with other compressors, yui did not give a lot of information, closing seemed to give me a hint, but did not help)

Then I squeezed assets locally, then I pushed for production. (To compress locally, use RAILS_ENV=production rake assets:precompile )

I ran on the server, and this happened when javascript errors appeared. It was basically a mistaken file merge (mainly due to something commented out). I got rid of these lines and returned to production. Everything succeeded.

I returned the uglifier, deleted the precompiled assets under public/assets/ and threw it back to production.

Hope this helps someone!

+9
Aug 28 '15 at 21:50
source share

Just in this heads-up, I had the same problem and what happened when precompiling assets in the production environment (and clicking on Heroku) several of my JS files were inserted with foreign characters, in accordance with ...

 <<<<<<<<HEAD =========== >>>>>>(random alphanumeric key) 

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

+2
Jan 11 '15 at 9:58
source share

For some reason, on heroku, and also when I ran the above code to โ€œguessโ€ javascript in the rails console, it did not report the error line number !. This is just a ruby โ€‹โ€‹wrapper for UglifyJS, which you can use here here https://skalman.imtqy.com/UglifyJS-online/ .

So, I just copied and pasted the js file into it and it reported the line number. Very simple.

+2
Apr 05 '17 at 19:24
source share

Check that the new JS files you added to the app include plugins and others added by Bower or something like that.

Try adding one by one to find the file with the problem. In my case, it was in anchor-scroll.js . When I changed the use of anchor-scroll.min , the rake is working fine.

Change this:

 //= require anchor-scroll/scroll 

For:

 //= require anchor-scroll/scroll.min 
+1
Apr 14 '16 at 23:37
source share

My problem was two successful calls.

First was mqtt onSuccess :

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

which I solved with:

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

and the second is the success of Ajax. Linter will show you

Error: shortening expected method

but everything will work correctly.

+1
Jul 27 '16 at 6:38
source share

"/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 is a gap between the selected area (between the ruby, backslash and the house).

I donโ€™t know if it was a typo, but it could be your problem, because Rails does not like spaces in directory names. Rename this folder and try to run the code again.

-four
Oct 09 '13 at 20:17
source share



All Articles