SassC::SyntaxError: Error: Invalid CSS after "}": - ruby-on-rails

I'm trying to precompile + minify my js and css assets.
If I run: rake assets:precompile
Then it runs fine, but doesn't minify.
If I run: SECRET_KEY_BASE=rake secretRAILS_ENV=production rake assets:precompile
Then it returns an error message and doesn't compile: SassC::SyntaxError: Error: Invalid CSS after "}": expected 1 selector or at-rule, was '!function(){if("und' on line 17881 of stdin
I've tried updating various gems, changing some of the CSS, adding #import to application.scss, etc but none of it seems to be working.
Here's the full error message:
rake aborted!
SassC::SyntaxError: Error: Invalid CSS after "}": expected 1 selector or at-rule, was '!function(){if("und'
on line 17881 of stdin
>> }
-^
stdin:17881
/usr/local/rvm/gems/ruby-2.4.1/gems/sassc-2.0.0/lib/sassc/engine.rb:49:in `render'
/usr/local/rvm/gems/ruby-2.4.1/gems/sassc-rails-2.1.0/lib/sassc/rails/compressor.rb:29:in `call'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/sass_compressor.rb:28:in `call'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:75:in `call_processor'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `call_processors'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/loader.rb:60:in `block in load'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/loader.rb:44:in `load'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:47:in `load'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/base.rb:66:in `find_asset'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/base.rb:73:in `find_all_linked_assets'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:142:in `block in find'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:228:in `block in stat_tree'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `each'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `stat_directory'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:227:in `stat_tree'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `each'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `block in logical_paths'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `each'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `logical_paths'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:140:in `find'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:186:in `compile'
/usr/local/rvm/gems/ruby-2.4.1#global/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/rake/sprocketstask.rb:147:in `with_logger'
/usr/local/rvm/gems/ruby-2.4.1#global/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => assets:precompile
What am I missing that will let it precompile and minify my js and css?

For anyone searching for this, in the end I just deleted two instances in my CSS and JS that included the problematic line (!function(){if().
Still not sure why they caused this error but as they were not actively used lines anyway (related to videos, which I don't currently use) I was happy enough to just delete and compile without them.

I met the same problem.
to solve it, the key is find what is the content of "stdin", so we have to modify your local gem file and add debug outputs:
# edit (/home/siwei/.asdf/installs/ruby/3.0.4/lib/ruby/gems/3.0.0/gems/sassc-rails-2.1.2/lib/sassc/rails/compressor.rb)
def call(*args)
input = if defined?(data)
data # sprockets 2.x
else
args[0][:data] #sprockets 3.x
end
# add these debug lines of code
puts "=== input is: "
File.write('/tmp/temp_scss', input)
puts "=== input end "
SassC::Engine.new(
input,
{
style: :compressed
}
).render
end
then run command:
RAILS_ENV=production bundle exec rails assets:precompile
then you will meet error, no worry, check out the file /tmp/temp_scss, find the "line 17881 of stdin", you will find the syntax error.
e.g. my error looks like:
just fix this bug and everything goes fine.

Related

ArgumentError: wrong number of arguments with `bundle exec rake db:migrate`

I'm trying to install Discourse in macOS for development, following the steps mentioned here: https://meta.discourse.org/t/beginners-guide-to-install-discourse-on-macos-for-development/15772
After following the steps mentioned here: https://community.unix.com/t/macos-catalina-discourse-development-environment-notes/378448 to run bundle install, I tried to use bundle exec rake db:migrate (as stated in installation instructions), and it showed me this error:
% bundle exec rake db:migrate
rake aborted!
ArgumentError: wrong number of arguments (given 1, expected 0; required keywords: site_setting_name, title, raw)
/Users/jonathanhung/discourse/lib/seed_data/topics.rb:126:in `create_topic'
/Users/jonathanhung/discourse/lib/seed_data/topics.rb:16:in `block (2 levels) in create'
/Users/jonathanhung/discourse/lib/seed_data/topics.rb:15:in `each'
/Users/jonathanhung/discourse/lib/seed_data/topics.rb:15:in `block in create'
/Users/Tim/bin/gems/i18n-1.8.10/lib/i18n.rb:314:in `with_locale'
/Users/jonathanhung/discourse/lib/seed_data/topics.rb:14:in `create'
(eval):14:in `block (2 levels) in run_file'
/Users/Tim/bin/gems/seed-fu-2.3.9/lib/seed-fu/runner.rb:46:in `eval'
/Users/Tim/bin/gems/seed-fu-2.3.9/lib/seed-fu/runner.rb:46:in `block (2 levels) in run_file'
/Users/Tim/bin/gems/seed-fu-2.3.9/lib/seed-fu/runner.rb:58:in `block in open'
/Users/Tim/bin/gems/seed-fu-2.3.9/lib/seed-fu/runner.rb:57:in `open'
/Users/Tim/bin/gems/seed-fu-2.3.9/lib/seed-fu/runner.rb:57:in `open'
/Users/Tim/bin/gems/seed-fu-2.3.9/lib/seed-fu/runner.rb:36:in `block in run_file'
/Users/Tim/bin/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `block in transaction'
/Users/Tim/bin/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/transaction.rb:310:in `block in within_new_transaction'
/Users/Tim/bin/gems/activesupport-6.1.3.2/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/Users/Tim/bin/gems/activesupport-6.1.3.2/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/Users/Tim/bin/gems/activesupport-6.1.3.2/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/Users/Tim/bin/gems/activesupport-6.1.3.2/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/Users/Tim/bin/gems/activesupport-6.1.3.2/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/Users/Tim/bin/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/transaction.rb:308:in `within_new_transaction'
/Users/Tim/bin/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `transaction'
/Users/Tim/bin/gems/activerecord-6.1.3.2/lib/active_record/transactions.rb:209:in `transaction'
/Users/Tim/bin/gems/seed-fu-2.3.9/lib/seed-fu/runner.rb:35:in `run_file'
/Users/Tim/bin/gems/seed-fu-2.3.9/lib/seed-fu/runner.rb:26:in `block in run'
/Users/Tim/bin/gems/seed-fu-2.3.9/lib/seed-fu/runner.rb:25:in `each'
/Users/Tim/bin/gems/seed-fu-2.3.9/lib/seed-fu/runner.rb:25:in `run'
/Users/Tim/bin/gems/seed-fu-2.3.9/lib/seed-fu.rb:29:in `seed'
/Users/jonathanhung/discourse/lib/tasks/db.rake:222:in `block in <main>'
/Users/Tim/bin/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'
/Users/jonathanhung/.rbenv/versions/3.0.1/bin/bundle:23:in `load'
/Users/jonathanhung/.rbenv/versions/3.0.1/bin/bundle:23:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Does anyone know what I could do to fix it? Thank you for your feedback.
Note: I'm using macOS version 11.4
Downgrading ruby from 3.0.0 to 2.7.2 solves the issue
https://meta.discourse.org/t/discourse-installation-fails-on-database-migration/194867/5
Or you can change create_topic(params) to create_topic(**params) (update_topic as well)

Rails won't precompile assets due to Uglifier error (Uglifier::Error)

When running RAILS_ENV=production rake assets:precompile, I get an error about Uglifier, as shown below:
root#4d24cd4a5e73:/myapp# RAILS_ENV=production rake assets:precompile
Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
I, [2021-01-05T03:02:20.063081 #1157] INFO -- : Writing /myapp/public/assets/devise-47cffe5a2e3ba6e30007c165a43ffece5c9f22dffd9aa74fd1d16997604531d6.js
I, [2021-01-05T03:02:20.064339 #1157] INFO -- : Writing /myapp/public/assets/devise-47cffe5a2e3ba6e30007c165a43ffece5c9f22dffd9aa74fd1d16997604531d6.js.gz
I, [2021-01-05T03:02:20.891999 #1157] INFO -- : Writing /myapp/public/assets/devise-21d500da162dd967a369767d6e63a850741756ad45ad5ee5585b3000404b5aec.css
I, [2021-01-05T03:02:20.892583 #1157] INFO -- : Writing /myapp/public/assets/devise-21d500da162dd967a369767d6e63a850741756ad45ad5ee5585b3000404b5aec.css.gz
I, [2021-01-05T03:02:23.132038 #1157] INFO -- : Writing /myapp/public/assets/theme_metrica-d858c65c360f07333101ab2929374a9a0a32010684107f1342b8bd3fd904619f.css
I, [2021-01-05T03:02:23.132473 #1157] INFO -- : Writing /myapp/public/assets/theme_metrica-d858c65c360f07333101ab2929374a9a0a32010684107f1342b8bd3fd904619f.css.gz
I, [2021-01-05T03:02:24.038975 #1157] INFO -- : Writing /myapp/public/assets/default-d59db161d4cc7a0b511555c8e661e0d8b2b4b03baa22106b7e07cbf356664725.js
I, [2021-01-05T03:02:24.039591 #1157] INFO -- : Writing /myapp/public/assets/default-d59db161d4cc7a0b511555c8e661e0d8b2b4b03baa22106b7e07cbf356664725.js.gz
rake aborted!
Uglifier::Error:
/usr/local/bundle/gems/uglifier-4.2.0/lib/uglifier.rb:291:in `parse_result'
/usr/local/bundle/gems/uglifier-4.2.0/lib/uglifier.rb:221:in `run_uglifyjs'
/usr/local/bundle/gems/uglifier-4.2.0/lib/uglifier.rb:166:in `compile'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/compressing.rb:65:in `block in js_compressor='
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/legacy_proc_processor.rb:31:in `call'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:75:in `call_processor'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `call_processors'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/loader.rb:60:in `block in load'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/loader.rb:44:in `load'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:47:in `load'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/base.rb:66:in `find_asset'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/base.rb:73:in `find_all_linked_assets'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:142:in `block in find'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:228:in `block in stat_tree'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `each'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `stat_directory'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:227:in `stat_tree'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `each'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `block in logical_paths'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `each'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `logical_paths'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:140:in `find'
/usr/local/bundle/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:186:in `compile'
/usr/local/bundle/gems/sprockets-rails-3.2.2/lib/sprockets/rails/task.rb:67:in `block (3 levels) in define'
/usr/local/bundle/gems/sprockets-3.7.2/lib/rake/sprocketstask.rb:147:in `with_logger'
/usr/local/bundle/gems/sprockets-rails-3.2.2/lib/sprockets/rails/task.rb:66:in `block (2 levels) in define'
/usr/local/bundle/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
root#4d24cd4a5e73:/myapp#
It turns out it's due to ckeditor5 being used within my application. If I remove the following line from my application.js file, then it precompiles just fine:
//= require ckeditor5/build/ckeditor.js
I have ran into this situation before and had to just simply modify my config/environment/production.rb file to modify this:
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
to
# Compress JavaScripts and CSS.
config.assets.js_compressor = Uglifier.new(:harmony => true)
This has worked for quite some time, but now I'm running into the same error. The solution proposed at Ruby on Rails Error: Uglifier::Error: Unexpected token: operator (<) suggests doing the exact same thing, but this is no longer working for me.
I encountered this in 2 different Rails apps (same parse_result message and version of uglifier) and found it doesn't support ES6, so some recently updated dependencies were no longer getting compressed by uglifier. I solved it by switching to terser, which wasn't a difficult conversion:
https://github.com/publiclab/plots2/issues/11232, fix in https://github.com/publiclab/plots2/pull/11243
Easy solution: switch to "Terser"
Here's the ruby wrapper for Terser: https://github.com/ahorek/terser-ruby.
I don't think Uglifier is being maintained anymore (but I could be wrong about that).
To workaround this problem, I took ckeditor5 out of the application.js file, relocated its folder from app/javascripts/ckeditor5 to public/ckeditor5 and then added a line in my application.html.erb layouts file:
<%= javascript_include_tag "/ckeditor5/build/ckeditor.js", media: :all, 'data-turbolinks-track': "reload" %>
Solved my problem.
If you are using
webpacker > 5.0
resolved_paths has been replaced with the additional_paths for reference click here
In /config/webpacker.yml
replace resolved_paths with additional_paths

Getting ExecJS when compiling rassets:precompile against production

So I am running into an odd issue. I cannot precompile assets on Rails 5 against production. I keep getting the same error message, irrespective if I precompile on the server itself or on my local environment.
georg$ RAILS_ENV=production bundle exec rake assets:precompile
rake aborted!
ExecJS::RuntimeError: SyntaxError: Unexpected token: name ($)
get#(execjs):3538:630
(execjs):4058:47
(execjs):1:46
global code#(execjs):1:58
/Users/georg/.rvm/gems/ruby-2.2.4/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:39:in `exec'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:21:in `eval'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:46:in `call'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/uglifier-3.2.0/lib/uglifier.rb:195:in `run_uglifyjs'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/uglifier-3.2.0/lib/uglifier.rb:157:in `compile'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/uglifier_compressor.rb:53:in `call'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/uglifier_compressor.rb:28:in `call'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:75:in `call_processor'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `call_processors'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/loader.rb:60:in `block in load'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/loader.rb:44:in `load'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:47:in `yield'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:47:in `load'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/base.rb:66:in `find_asset'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/base.rb:73:in `find_all_linked_assets'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:142:in `block in find'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:228:in `block in stat_tree'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `each'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `stat_directory'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:227:in `stat_tree'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:231:in `block in stat_tree'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `each'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `stat_directory'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:227:in `stat_tree'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:231:in `block in stat_tree'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `each'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `stat_directory'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:227:in `stat_tree'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:231:in `block in stat_tree'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `each'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `stat_directory'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:227:in `stat_tree'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:105:in `each'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:105:in `block in logical_paths'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:104:in `each'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:104:in `logical_paths'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:140:in `find'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:185:in `compile'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-3.7.1/lib/rake/sprocketstask.rb:147:in `with_logger'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
/Users/georg/.rvm/gems/ruby-2.2.4/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/Users/georg/.rvm/gems/ruby-2.2.4/bin/ruby_executable_hooks:15:in `eval'
/Users/georg/.rvm/gems/ruby-2.2.4/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
To solve the issue I did the following:
1.) I have a subfolder structure I am referring to under assets/javascript, so I added that to the asset path and I thought that may be the issue - but apparently it isn't. I read the paths in like this:
Dir.glob("#{Rails.root}/app/assets/javascripts/**/").each do |path|
config.assets.paths << path
end
2.) I removed all references from application.js - it is empty and I still get the error.
3.) I removed / added therubyracer
# gem 'therubyracer', platforms: :ruby
4.) I installed and updated the execjs gem independently
5.) Eventually, I was running out of ideas. Given that I get the error when there's nothing to compile.
My environment:
georg$ rails -v
Rails 5.0.5
georg$ ruby -v
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-darwin16]
The compiling was done on OSx and Debian.
Any hints are much appreciated!!
The issue was with a custom js file in the tree. Given that there are plenty of js files included in the applciation.js it is obviously a painful way of trial and error to get to the bottom of the issue given the limited information I got from the trace. It would be interesting to know if there are ways to get more information in return to avoid lengthy inefficient debug sessions.
For the time being, I removed all js, added them one-by-one and run a precompile till I hit the offending code.

Assets Precompile When Explicitly Invoked, Breaks During Capistrano Deployment

I am using Rails 4.2, and Capistrano 3. When I run bundle exec rake assets:precompile, everything works out nice and dandy, however when I use Capistrano to deploy the site, I get this error during the asset:precompile step.
Tasks: TOP => deploy:assets:precompile
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as xxx#123.45.67.89: rake exit status: 1
rake stdout: rake aborted!
Sass::SyntaxError: Invalid CSS after " */": expected "}", was ""
(sass):6831
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sass-3.4.19/lib/sass/scss/parser.rb:1161:in `expected'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sass-3.4.19/lib/sass/scss/parser.rb:1097:in `expected'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sass-3.4.19/lib/sass/scss/parser.rb:1092:in `tok!'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sass-3.4.19/lib/sass/scss/parser.rb:639:in `block'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sass-3.4.19/lib/sass/scss/parser.rb:631:in `ruleset'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sass-3.4.19/lib/sass/scss/parser.rb:656:in `block_child'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sass-3.4.19/lib/sass/scss/parser.rb:649:in `block_contents'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sass-3.4.19/lib/sass/scss/parser.rb:117:in `stylesheet'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sass-3.4.19/lib/sass/scss/parser.rb:42:in `parse'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sass-3.4.19/lib/sass/engine.rb:403:in `_to_tree'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sass-3.4.19/lib/sass/engine.rb:278:in `render'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/sass_compressor.rb:48:in `call'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/sass_compressor.rb:28:in `call'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/processor_utils.rb:75:in `call_processor'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/processor_utils.rb:56:in `call_processors'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/loader.rb:60:in `block in load'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/loader.rb:318:in `fetch_asset_from_dependency_cache'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/loader.rb:44:in `load'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/cached_environment.rb:47:in `yield'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/cached_environment.rb:47:in `load'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/base.rb:66:in `find_asset'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/base.rb:73:in `find_all_linked_assets'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/manifest.rb:142:in `block in find'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/path_utils.rb:225:in `block in stat_tree'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/path_utils.rb:209:in `block in stat_directory'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/path_utils.rb:206:in `each'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/path_utils.rb:206:in `stat_directory'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/path_utils.rb:224:in `stat_tree'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/legacy.rb:105:in `each'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/legacy.rb:105:in `block in logical_paths'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/legacy.rb:104:in `each'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/legacy.rb:104:in `logical_paths'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/manifest.rb:140:in `find'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/sprockets/manifest.rb:168:in `compile'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-rails-2.3.3/lib/sprockets/rails/task.rb:70:in `block (3 levels) in define'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.0/lib/rake/sprocketstask.rb:147:in `with_logger'
/home/xxx/Sites/my-app/shared/bundle/ruby/2.2.0/gems/sprockets-rails-2.3.3/lib/sprockets/rails/task.rb:69:in `block (2 levels) in define'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
rake stderr: Nothing written
I have noticed that if I remove the line *= require styles in my application.css file, it successfully deploys, but obviously that is not the solution I am looking for. My assets/stylesheets file-structure is shown below:
Running the following command compiles assets locally in your dev environment:
rake assets:precompile
During deployment capistrano the following task is being invoked (as you can see on top of your backtrace):
cap env_name deploy:assets:precompile
which on it's part invokes this on remote server:
rake assets:precompile
Asset precompilation in development environment ignores syntax errors.
Try running this command locally to find and fix those errors:
RAILS_ENV=production rake assets:precompile --trace

rake assets:precompile attempting to connect to database

I'm attempting to debug why my application is attempting to connect to my database when I run rake assets:precompile --trace.
I'm probably missing something in the stack trace...anyone see the pertinent line?
DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in ActionController::Base instead. (called from <top (required)> at /Users/Kyle/Desktop/skateparks-web/config/application.rb:4)
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/bin/ruby /Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in ActionController::Base instead. (called from <top (required)> at /Users/Kyle/Desktop/skateparks-web/config/application.rb:4)
** 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
rake aborted!
FATAL: database "skateparks_production" does not exist
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:1161:in `initialize'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:1161:in `new'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:1161:in `connect'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:316:in `initialize'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:27:in `new'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:27:in `postgresql_connection'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:277:in `new_connection'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:287:in `checkout_new_connection'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:235:in `block (2 levels) in checkout'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `loop'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `block in checkout'
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:229:in `checkout'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `connection'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in `retrieve_connection'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/model_schema.rb:308:in `clear_cache!'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activerecord-3.2.0/lib/active_record/railtie.rb:91:in `block (2 levels) in <class:Railtie>'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activesupport-3.2.0/lib/active_support/callbacks.rb:418:in `_run__2041913228368879189__prepare__1991931652306887621__callbacks'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activesupport-3.2.0/lib/active_support/callbacks.rb:405:in `__run_callback'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activesupport-3.2.0/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activesupport-3.2.0/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/actionpack-3.2.0/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/actionpack-3.2.0/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/railties-3.2.0/lib/rails/application/finisher.rb:48:in `block in <module:Finisher>'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/railties-3.2.0/lib/rails/initializable.rb:30:in `instance_exec'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/railties-3.2.0/lib/rails/initializable.rb:30:in `run'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/railties-3.2.0/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/railties-3.2.0/lib/rails/initializable.rb:54:in `each'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/railties-3.2.0/lib/rails/initializable.rb:54:in `run_initializers'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/railties-3.2.0/lib/rails/application.rb:136:in `initialize!'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/railties-3.2.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/Kyle/Desktop/skateparks-web/config/environment.rb:5:in `<top (required)>'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:251:in `require'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:251:in `block in require'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:251:in `require'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/railties-3.2.0/lib/rails/application.rb:103:in `require_environment!'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/railties-3.2.0/lib/rails/application.rb:292:in `block (2 levels) in initialize_tasks'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/actionpack-3.2.0/lib/sprockets/assets.rake:89:in `block (2 levels) in <top (required)>'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:174:in `each'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/actionpack-3.2.0/lib/sprockets/assets.rake:56:in `block (3 levels) in <top (required)>'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:90:in `block (2 levels) in top_level'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:90:in `block in top_level'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:62:in `block in run'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/bin/rake:19:in `load'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/bin/rake:19:in `<main>'
Tasks: TOP => environment
rake aborted!
Command failed with status (1): [/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/bi...]
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/file_utils.rb:53:in `block in create_shell_runner'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/file_utils.rb:45:in `call'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/file_utils.rb:45:in `sh'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/file_utils_ext.rb:36:in `sh'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/file_utils.rb:78:in `ruby'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/file_utils_ext.rb:36:in `ruby'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/actionpack-3.2.0/lib/sprockets/assets.rake:9:in `ruby_rake_task'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/actionpack-3.2.0/lib/sprockets/assets.rake:17:in `invoke_or_reboot_rake_task'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/actionpack-3.2.0/lib/sprockets/assets.rake:25:in `block (2 levels) in <top (required)>'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:90:in `block (2 levels) in top_level'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:90:in `block in top_level'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:62:in `block in run'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/bin/rake:19:in `load'
/Users/Kyle/.rvm/gems/ruby-1.9.2-p290#skateparks/bin/rake:19:in `<main>'
Tasks: TOP => assets:precompile
rake assets:precompile initializes your app by default, which includes connection to the database.
Inside config/application.rb you can add this, but see the link below for warnings about it:
config.assets.initialize_on_precompile = false
Rails Guide on Precompiling Assets
I had that same problem. After updating Sprockets to version 3, whenever I tried to precompile the assets locally (development), however using the settings of the production environment, I had this error:
rake aborted!
Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add gem 'pg' to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
Because in my local (development) I use MySQL and in the server (production), I use Postgres.
The answer marked as resolved does not work for me, because config.assets.initialize_on_precompile is not available in Rails 4.2.1.
To solve, I followed 3 simple steps:
In your Gemfile, add: gem "activerecord-nulldb-adapter"
In database.yml, change the adapter as follow:
production:
adapter: <%= ENV['DB_ADAPTER'] ||= 'postgresql' %>
To compile your production assets locally. run in your terminal
DB_ADAPTER=nulldb RAILS_ENV=production rake assets:precompile
This solutions solved to me and I sawyed here.
Newer versions of Rails do not load the database during asset precompile. However, initializers will often cause it to load. This can be frustrating to debug, because the error omits the stack trace.
./bin/rails assets:precompile
(in ~/src/nautilus)
rake aborted!
ActiveRecord::NoDatabaseError: FATAL: database "your_app_development" does not exist
bundler: failed to load command: rake (~/src/your_app/vendor/bundle/ruby/2.6.0/bin/rake)
NoMethodError: undefined method `reject' for nil:NilClass
The less than helpful error.
So, how do we figure out where the problem is?
Move all the initializers out of config/initializers then run ./bin/rails assets:precompile.
If it works, great, you know the problem is in one of those files.
Move them back one by one till you find the offending file(s).
Now that the problem was found, how do we fix it?
Then when I find an initialilzer that has a problem I wrap it with the following check:
unless ARGV.include? "assets:precompile"
# ...
end
I prefer this over the nulldb because it reduces the number of dependencies I have to maintain in the app.
If it makes sense in your situation, you can choose against which environment assets:precompile should work, with the following command:
rake assets:precompile:all RAILS_ENV=development RAILS_GROUPS=assets
This make sense for my deployment because usually:
I make rake to generates assets on my development machine (because the memory of my vps is somehow limited)
I zip all the application with the assets generated in public/assets
I transfer the zip to the vps ans unzip the package there
Hope it helps.
Check your configuration files (in all environments). If for example
rake assets:precompile
works in development, but you are having issues in production
RAILS_ENV=production bundle exec rake assets:precompile
then you most likely have a reference to active record in your /config/environments/production.rb
config.active_record.dump_schema_after_migration = false
In order to avoid that altogether if you are planning on not taking advantage of active record or employing a NoSQL such as mongo, you may wish to initialize your new app as follows:
rails new myApp --skip-active-record
which is equivalent to -O (capital O) as far as I am concerned.
Maybe this won't work for all cases but I was able to avoid Rails attempting to connect to the database on the rake assets:* tasks by surrounding the code in some places with the snippet below on the /config/routes.rb:
unless defined?(::Rake::SprocketsTask)
devise_for ...
#...
end
devise_scope ...
#...
end
end
Sometimes code which depends on external services or environment variables will get loaded because of code on the initializer files which are not required for assets to be precompiled.
I've recently faced a similar issue and the responses above didn't work for me. I've found the file on config/initializers/ that was causing the issue and wrapped it with the following code:
unless defined?(::Rake::SprocketsTask)
#...
end
The snippet above will skip the code within it when running rake assets:precompile or others like rake assets:clean as well.
Hopefully this will help others in the future!

Resources