Reputation: 31
When deploying my Rails app on heroku I get the following error,
remote: Bundle completed (163.81s) remote: Cleaning up the bundler cache. remote: -----> Installing node-v8.10.0-linux-x64 remote: -----> Detecting rake tasks remote: -----> Preparing app for Rails asset pipeline remote: Running: rake assets:precompile remote: Yarn executable was not detected in the system. remote: Download Yarn at https://yarnpkg.com/en/docs/install remote: rake aborted! remote: Uglifier::Error: Unexpected token punc «;», expected punc «,» remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/uglifier-4.1.20/lib/uglifier.rb:234:in `parse_result' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/uglifier-4.1.20/lib/uglifier.rb:216:in `run_uglifyjs' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/uglifier-4.1.20/lib/uglifier.rb:168:in `compile' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/compressing.rb:65:in `block in js_compressor=' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/legacy_proc_processor.rb:31:in `call' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:75:in `call_processor' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:57:in `block in call_processors' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `reverse_each' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `call_processors' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:134:in `load_from_unloaded' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:60:in `blockin load' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:44:in `load' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:20:in `block in initialize' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:47:in `load' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:66:in `find_asset' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:73:in `find_all_linked_assets' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:142:in `block in find' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:228:in `block in stat_tree' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:212:in `block in stat_directory' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `each' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `stat_directory' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:227:in `stat_tree' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `each' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `block in logical_paths' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `each' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `logical_paths' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:140:in `find' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:186:in `compile' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/rake/sprocketstask.rb:147:in `with_logger' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/rake-12.3.2/exe/rake:27:in `' remote: Tasks: TOP => assets:precompile remote: (See full trace by running task with --trace) remote: remote: ! remote: ! Precompiling assets failed. remote: ! remote: ! Push rejected, failed to compile Ruby app. remote: remote: ! Push failed remote: Verifying deploy...
I've already modify the line in production.rb
to,
config.assets.js_compressor = Uglifier.new(harmony: true)
but error persists.
Upvotes: 3
Views: 3246
Reputation: 30216
It looks like the problem arises because your version of Sprockets or Rails can't play nicely with the newer Uglifier. At least in Rails 3.2.22, .map
files get generated and then treated as whatever the next suffix up is. E.g. Sprockets tries to compress application.js.map
as if it were a js file.
One solution is to tell Sprockets to ignore map files by adding a line to your config/environments/production.rb
file (or whatever config file you please):
config.assets.precompile[0] = Proc.new { |path| !File.extname(path).in?(['.js', '.css', '.map']) }
Before you copy-paste the code above, you should verify that you're replacing the right item(s) in the pre-existing config.assets.precompile
array. This array holds procs which determine which files get processed. For me, there were two items in the array, and the first one was as follows:
#<Proc:0x0055819620f6f8@/home/me/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-3.2.22/lib/rails/application/configuration.rb:48>
Looking at the indicated location (gems/railties-3.2.22/lib/rails/application/configuration.rb:48
) for the definition of the foregoing proc reveals:
Proc.new{ |path| !File.extname(path).in?(['.js', '.css']) }
...which selects every non-js, non-css file. Adding '.map'
to that list of exclusions would prevent the .map
files from being fed through the compressor.
Upvotes: 2