Ruby on Rails Error: Uglifier::Error: Unexpected token: operator (<) - ruby-on-rails

Whenever I run rake assets:precompile RAILS_ENV=production in my command line, I get this error which prevents me from precompiling my assets.
Below is the complete error displayed in the command line:
rake aborted!
Uglifier::Error: Unexpected token: operator (<)
/usr/local/rvm/gems/ruby-2.3.4/gems/uglifier-4.1.4/lib/uglifier.rb:234:in parse_result'
/usr/local/rvm/gems/ruby-2.3.4/gems/uglifier-4.1.4/lib/uglifier.rb:216:in run_uglifyjs'
/usr/local/rvm/gems/ruby-2.3.4/gems/uglifier-4.1.4/lib/uglifier.rb:168:in compile'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/compressing.rb:65:in block in js_compressor='
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/legacy_proc_processor.rb:31:in call'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:75:in call_processor'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:57:in block in call_processors'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in reverse_each'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in call_processors'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/loader.rb:134:in load_from_unloaded'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/loader.rb:60:in block in load'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/loader.rb:317:in fetch_asset_from_dependency_cache'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/loader.rb:44:in load'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:20:in block in initialize'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:47:in load'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/base.rb:66:in find_asset'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/base.rb:73:in find_all_linked_assets'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:142:in block in find'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:114:in block (2 levels) in logical_paths'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:228:in block in stat_tree'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:212:in block in stat_directory'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in each'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in stat_directory'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:227:in stat_tree'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:105:in each'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:105:in block in logical_paths'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:104:in each'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:104:in logical_paths'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:140:in find'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:185:in compile'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:68:in block (3 levels) in define'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-3.7.1/lib/rake/sprocketstask.rb:147:in with_logger'
/usr/local/rvm/gems/ruby-2.3.4/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in block (2 levels) in define'
/usr/local/rvm/gems/ruby-2.3.4/gems/rake-12.3.0/exe/rake:27:in <top (required)>'
/usr/local/rvm/gems/ruby-2.3.4/bin/ruby_executable_hooks:15:in eval'
/usr/local/rvm/gems/ruby-2.3.4/bin/ruby_executable_hooks:15:in <main>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
What exactly do I need to do to fix this error?

I encountered the same error. Interestingly, it was triggered by the direct_upload.js file that Rails itself recommends for ActiveStorage! I found the solution here: https://github.com/lautis/uglifier/issues/127
Try replacing
config.assets.js_compressor = :uglifier
with
config.assets.js_compressor = Uglifier.new(harmony: true)
in config/environments/production.rb

You can always check the JS files by parsing it with the uglifier compiler.
Open your rails console
const JS_FOLDER = [file1_path, file2_path];
JS_FOLDER.each do. |file_name|
puts "#{file_name}"
puts Uglifier.compile(File.read(file_name))
end
And there you will have your corrupted file.

The trace is indicating that you have a syntax error in one of your JavaScript files. If you look in your browser's console, it might tell you where the error is.
If not, I'd suggest removing JS files until you find the culprit, and then commenting out lines in the offending file until you find the error. A binary search method might be helpful; start by removing roughly half your JS files and then trying the precompilation. If the error still occurs, then remove half of what's left and retry. When the error stops occurring, then you know which group of files contains the offending file, so you can back up one step, remove everything but that group, and try recompiling again. Eventually you should figure out which file contains the error.
Once you've narrowed it down to a single file, you can use the same technique by commenting out about half the lines in the file, recompile, etc.

Related

Issue with Precompililing Assets in Rails App

My rails app uses Rails 3.2.15. When I try to deploy to Heroku, I get the error:
Asset logical path has no extension: ]
In other examples I've seen of the "asset logical path" error, the element after the colon was the filename. Why does it think there is a file called "]"?
Here is the full error:
/tmp/build_4d16c741-7af1-443a-b0f0-8aad5d279d8f/vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2.backport2/lib/sprockets/asset.rb:36:in `initialize'
/tmp/build_4d16c741-7af1-443a-b0f0-8aad5d279d8f/vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2.backport2/lib/sprockets/base.rb:380:in `new'
/tmp/build_4d16c741-7af1-443a-b0f0-8aad5d279d8f/vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2.backport2/lib/sprockets/base.rb:380:in `build_asset'
/tmp/build_4d16c741-7af1-443a-b0f0-8aad5d279d8f/vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2.backport2/lib/sprockets/index.rb:94:in `block in build_asset'
/tmp/build_4d16c741-7af1-443a-b0f0-8aad5d279d8f/vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2.backport2/lib/sprockets/caching.rb:58:in `cache_asset'
/tmp/build_4d16c741-7af1-443a-b0f0-8aad5d279d8f/vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2.backport2/lib/sprockets/index.rb:93:in `build_asset'
/tmp/build_4d16c741-7af1-443a-b0f0-8aad5d279d8f/vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2.backport2/lib/sprockets/base.rb:287:in `find_asset'
/tmp/build_4d16c741-7af1-443a-b0f0-8aad5d279d8f/vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2.backport2/lib/sprockets/index.rb:61:in `find_asset'
/tmp/build_4d16c741-7af1-443a-b0f0-8aad5d279d8f/vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2.backport2/lib/sprockets/manifest.rb:211:in `block in find_asset'
/tmp/build_4d16c741-7af1-443a-b0f0-8aad5d279d8f/vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2.backport2/lib/sprockets/manifest.rb:257:in `benchmark'
/tmp/build_4d16c741-7af1-443a-b0f0-8aad5d279d8f/vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2.backport2/lib/sprockets/manifest.rb:210:in `find_asset'
/tmp/build_4d16c741-7af1-443a-b0f0-8aad5d279d8f/vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2.backport2/lib/sprockets/manifest.rb:119:in `block in compile'
/tmp/build_4d16c741-7af1-443a-b0f0-8aad5d279d8f/vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2.backport2/lib/sprockets/manifest.rb:118:in `each'
/tmp/build_4d16c741-7af1-443a-b0f0-8aad5d279d8f/vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2.backport2/lib/sprockets/manifest.rb:118:in `compile'
/tmp/build_4d16c741-7af1-443a-b0f0-8aad5d279d8f/vendor/bundle/ruby/1.9.1/gems/sprockets-rails-2.0.0.backport1/lib/sprockets/rails/task.rb:60:in `block (3 levels) in define'
/tmp/build_4d16c741-7af1-443a-b0f0-8aad5d279d8f/vendor/bundle/ruby/1.9.1/gems/sprockets-2.2.2.backport2/lib/rake/sprocketstask.rb:146:in `with_logger'
/tmp/build_4d16c741-7af1-443a-b0f0-8aad5d279d8f/vendor/bundle/ruby/1.9.1/gems/sprockets-rails-2.0.0.backport1/lib/sprockets/rails/task.rb:59:in `block (2 levels) in define'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
!
! Precompiling assets failed.
!
! Push rejected, failed to compile Multipack app
I can recreate this error locally by running the following command
bundle exec rake assets:precompile
Some background:
I'm trying to integrate bootstrap-sass with my Rails 3.2 app. I followed the install instructions for 3.2.x outlined on the gem page:
https://github.com/twbs/bootstrap-sass
This works locally, but when I try to deploy, I get the errors described above.
If you're still on this or other people find this like I did, the trouble is with putting anything without an extension in the app/assets, you can safely move files to vendor/assets to avoid this error. For instance I recently installed third party files with bower and set their location to app/assets, but had trouble pushing to heroku. After pulling them out and into vendor/assets it worked fine. Also see: https://github.com/sstephenson/sprockets/issues/347 and https://github.com/stve/bower/pull/4/files
for the issue and resolution.

Log4r configurator throws exception instantiating EmailOutputter

I'm setting up Log4r using an XML configuration file, and I can't get the EmailOutputter to work correctly. Here's my outputter tag:
<outputter type="EmailOutputter" name="exception_email" trunc="false" level="ERROR" buffsize="10">
<formatter type="PatternFormatter" pattern="#{pattern}"/>
<server>#{smtp_address}</server>
<port>#{smtp_port}</port>
<domain>#{smtp_domain}</domain>
<from>logging##{smtp_domain}</from>
<to>exceptions#mydomain.com</to>
<subject>Log Report</subject>
<immediate_at>ERROR, FATAL</immediate_at>
</outputter>
I've triple and quadruple checked that all the XML variables are being passed in correctly using the RubyMine step-through debugger. The exception message is:
Uncaught exception: Problem creating outputter: uninitialized constant Log4r::Configurator::EmailOutputter
/usr/local/lib/ruby/gems/1.9.1/gems/log4r-1.1.10/lib/log4r/configurator.rb:87:in block in decode_xml'
/usr/local/lib/ruby/1.9.1/rexml/element.rb:905:inblock in each'
/usr/local/lib/ruby/1.9.1/rexml/xpath.rb:67:in each'
/usr/local/lib/ruby/1.9.1/rexml/xpath.rb:67:ineach'
/usr/local/lib/ruby/1.9.1/rexml/element.rb:905:in each'
/usr/local/lib/ruby/gems/1.9.1/gems/log4r-1.1.10/lib/log4r/configurator.rb:87:indecode_xml'
/usr/local/lib/ruby/gems/1.9.1/gems/log4r-1.1.10/lib/log4r/configurator.rb:82:in actual_load'
/usr/local/lib/ruby/gems/1.9.1/gems/log4r-1.1.10/lib/log4r/configurator.rb:56:inload_xml_file'
/root/src/upside/common/upside_logger.rb:16:in initialize'
/root/src/upside/common/logger_factory.rb:7:innew'
/root/src/upside/common/logger_factory.rb:7:in new_logger'
/root/src/upside/config/application.rb:30:inblock in '
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:34:in call'
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:34:inexecute_hook'
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:26:in block in on_load'
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:25:ineach'
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:25:in on_load'
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/railtie/configuration.rb:43:inbefore_configuration'
/root/src/upside/config/application.rb:29:in <class:Application>'
/root/src/upside/config/application.rb:15:in'
/root/src/upside/config/application.rb:14:in <top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:53:inrequire'
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:53:in block in <top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:50:intap'
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:50:in <top (required)>'
/root/src/upside/script/rails:6:inrequire'
/root/src/upside/script/rails:6:in `'
I've double checked the gem installation and the emailoutputter.rb is in the correct directory with the other outputters (which function correctly).
Thanks!
I found that the log4r file lib/log4r.rb to be missing the line require "log4r/outputter/emailoutputter". Adding this missing require to my Rails application in a config/initializer file allowed the EmailOutputter class available.

Translation bundling error in Ruby on Rails

I've recently updated my Ruby on Rails project and then when I try to run the
rake i18n:js:export command, I'm getting the following error
uninitialized constant I18n::INTERPOLATION_PATTERN
This happens in both windows 8.1 and centos6 machines.
My ruby version is: 1.8.7 in windows and 1.9.3 in CentOS6
Rails version: 3.0.9
I'm clueless in this spot and tried to find a solution, and couldn't find a correct one.
I'm using i18n-js version 2.1.2
I tried updating it to version 3.0.0.rc5 but still no luck.
Anyone came across any issues similar to this? I'm eagerly expecting a solution to fix this issue.
/* RESULT AFTER RUNNING WITH TRACE */
** Invoke i18n:js:export (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute i18n:js:export rake aborted! uninitialized constant I18n::INTERPOLATION_PATTERN
c:/Ruby193/lib/ruby/gems/1.9.1/gems/i18n-js-2.1.2/lib/i18n-js.rb:72:in
block in configured_segments'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/i18n-js-2.1.2/lib/i18n-js.rb:70:in
each'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/i18n-js-2.1.2/lib/i18n-js.rb:70:in
each_wit h_object'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/i18n-js-2.1.2/lib/i18n-js.rb:70:in
configur ed_segments'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/i18n-js-2.1.2/lib/i18n-js.rb:83:in
translat ion_segments'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/i18n-js-2.1.2/lib/i18n-js.rb:46:in
export!'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/i18n-js-2.1.2/lib/i18n-js/rake.rb:9:in
bloc k (2 levels) in <top (required)>'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/task.rb:236:in
call'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/task.rb:236:in
block i n execute'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/task.rb:231:in
each'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/task.rb:231:in
execute '
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/task.rb:175:in
block i n invoke_with_call_chain'
c:/Ruby193/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/task.rb:168:in
invoke_ with_call_chain'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/task.rb:161:in
`invoke'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/application.rb:149:in
invoke_task'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/application.rb:106:in
block (2 levels) in top_level'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/application.rb:106:in
each'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/application.rb:106:in
block in top_level'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/application.rb:115:in
run_with_threads'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/application.rb:100:in
top_level'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/application.rb:78:in
b lock in run'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/application.rb:165:in
standard_exception_handling'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/application.rb:75:in
r un' c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.1.1/bin/rake:33:in
' c:/Ruby193/bin/rake:23:in load'
c:/Ruby193/bin/rake:23:in' Tasks: TOP => i18n:js:export
Thanks
I know this is an outdated issue, but you may want to look at this recent SO question. It details how I ran into a similar issue and how it was resolved:
upgrading to ruby 2.3.0 NameError: uninitialized constant I18n::Config::Backend
Look through your rake files and see if you have any references to the Translation helper.
Removing include ActionView::Helpers::TranslationHelper and replacing (t "some_text") with (I18n.t "some_text") completely resolved the issue.

How to use GPUImage with Rubymotion?

I am developing a Rubymotion app. I want to use the GPUImage pod so I add it to my Rakefile and run rake pod:install. But at the end of the process I get this error:
sh: /Library/RubyMotion/bin/gen_bridge_metadata: Argument list too long
rake aborted!
Command failed with status (126): [RUBYOPT='' '/Library/RubyMotion/bin/gen_br...]
/Library/RubyMotion/lib/motion/project/xcode_config.rb:358:in `gen_bridge_metadata'
/Library/RubyMotion/lib/motion/project/vendor.rb:198:in `block in build_xcode'
/Library/RubyMotion/lib/motion/project/vendor.rb:144:in `chdir'
/Library/RubyMotion/lib/motion/project/vendor.rb:144:in `build_xcode'
/Library/RubyMotion/lib/motion/project/vendor.rb:43:in `build'
/Library/RubyMotion/lib/motion/project/builder.rb:64:in `block in build'
/Library/RubyMotion/lib/motion/project/builder.rb:63:in `each'
/Library/RubyMotion/lib/motion/project/builder.rb:63:in `build'
/Library/RubyMotion/lib/motion/project/app.rb:76:in `build'
/Users/jonathanclark/.rvm/gems/ruby-2.0.0-p247/gems/motion-cocoapods-1.4.0/lib/motion/project/cocoapods.rb:53:in `build_with_cocoapods'
/Library/RubyMotion/lib/motion/project/template/ios.rb:46:in `block (2 levels) in <top (required)>'
/Library/RubyMotion/lib/motion/project/template/ios.rb:63:in `block in <top (required)>'
Tasks: TOP => build:simulator
What does it all mean? How can I fix it?
This seems to be a bug in CocoaPods when there is lots of header files in a pod. I've submitted an issue for it and hopefully it will be fixed soon :)
https://github.com/CocoaPods/CocoaPods/issues/1670

"rake assets:precompile" gives punc error

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
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
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.
In my case, I was using es6 syntax ()=>{...} in js file.
Replacing it with function(){...} fixed the problem.
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!
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.
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.
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.
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
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.
"/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.

Resources