Cant run assets:precompile on heroku - ruby-on-rails

I am developing a Rails app on Windows 10 under Rails 5.2.1 and Ruby 2.4.4p296
I cannot run the command heroku run rake assets:precompile
I get this error:
C:\Users\Jaiel\Desktop\RubyOnRailsForum>heroku run rake assets:precompile --trace
Running rake assets:precompile --trace on ⬢ warm-mountain-15591... up, run.4644 (Free)
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke yarn:install (first_time)
** Execute yarn:install
Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
** Execute assets:precompile
Is it even an error? There are assets in the public/assets folder on heroku, however the JavaScript files seem to be not working or are conflicting each other as I also have a problem with them. For example links with method: :delete dont work in my App on Heroku in production environment.
Here is a thread about my problem that is maybe related to it

Try this
$rake assets:precompile (RAILS_ENV=production bundle exec rake assets:precompile is the exact rake task)
Since precompilation is done in production mode only, no need to explicitly specify the environment.
Update:
Try adding the below line to your Gemfile:
group :assets do
gem 'therubyracer'
gem 'sass-rails', " ~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
end
Then run bundle install.
Hope it will work :)

Related

assets:precompile fails with "File exists" on Rails 3.2.15 with Asset Pipeline

I am unable to precompile my assets for my Rails 3.2.15 asset pipeline enabled app.
Gemfile:
# Asset pipeline
group :assets do
gem 'sass-rails', '3.2.5'
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.3.0'
end
production.rb
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w( *.js *.css )
# Choose which compressors to use
# config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :scss
These are the commands i run:
bundle exec rake assets:clean RAILS_ENV=production --trace
bundle exec rake assets:precompile RAILS_ENV=production --trace
And i get the following error:
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/usr/bin/ruby1.9.1 /usr/local/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!
File exists - (/media/shared/code/me/app/tmp/cache/assets/sprockets%2F19d4dbfec65d2b21144310264f4d8c7320131106-63076-sh3p6h, /media/shared/code/me/app/tmp/cache/assets/D04/B00/sprockets%2F19d4dbfec65d2b21144310264f4d8c73)
/usr/lib/ruby/1.9.1/fileutils.rb:519:in `rename'
/usr/lib/ruby/1.9.1/fileutils.rb:519:in `block in mv'
/usr/lib/ruby/1.9.1/fileutils.rb:1515:in `block in fu_each_src_dest'
/usr/lib/ruby/1.9.1/fileutils.rb:1531:in `fu_each_src_dest0'
/usr/lib/ruby/1.9.1/fileutils.rb:1513:in `fu_each_src_dest'
/usr/lib/ruby/1.9.1/fileutils.rb:508:in `mv'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.15/lib/active_support/core_ext/file/atomic.rb:36:in `atomic_write'
Only the latter file (which seems to change every time i run the command) is visible on disk, the former seems to be a temp file which is created and then moved. It is not visible after seeing the error.
Any ideas what on earth this means?
I am running Ubuntu 12.04.3 LTS, Rubygems 2.1.6, Bundler 1.3.5 and Ruby 1.9.3p429
Thanks

spree 2.0.3 heroku error precompiling assets "Error: Out of stack space"

I'm trying to get a basic spree application working on Heroku. I'm following http://railsapps.github.io/rails-heroku-tutorial.html and the spree heroku guide.
I have edited config/application.rb to include config.assets.initialize_on_precompile = false
Then, because I need to precompile before I push to Heroku, I get stuck here:
D:\code\foo>rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
d:/RailsInstaller/Ruby1.9.3/bin/ruby.exe d:/RailsInstaller/Ruby1.9.3/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 tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
Error: Out of stack space
(in D:/code/foo/app/assets/javascripts/admin/all.js)
d:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/execjs-.4.0/lib/execjs/external_runtime.rb:68:in `extract_result'
...much more...
The all.js asset is unchanged from the original installation:
Running
rake assets:clean
before the precompile fixed this for somebody else, but not for me.
Browsing around it looks like this might be a windows specific issue? If it matters I used railsinstaller and I'm running Windows 7 on fairly new laptop.
Then, because I need to precompile before I push to Heroku
This is false. By default, Heroku's Cedar stack compiles your assets during slug compilation when you push to Heroku.
For more information see: https://devcenter.heroku.com/articles/rails-asset-pipeline

Why are my Rails assets getting precompiled twice?

I've noticed my assets seem to get compiled twice, which considerably slows down my deployment, as this step is the most time consuming part:
~/projects/rewportal(mapwidget ✔) rake assets:precompile
/home/ruy/.rvm/rubies/ruby-1.9.3-p194/bin/ruby /home/ruy/.rvm/gems/ruby-1.9.3-p194#rewportal/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
AssetSync: using /home/ruy/projects/rewportal/config/initializers/asset_sync.rb
AssetSync: using /home/ruy/projects/rewportal/config/initializers/asset_sync.rb
AssetSync: Syncing.
Using: Directory Search of /home/ruy/projects/rewportal/public/assets
Uploading: assets/application-5170f52c1dd49cb382d5135bee01d75e.js
[...]
Fetching files to flag for delete
Flagging 8 file(s) for deletion
Deleting: assets/active_admin-4ce46d089d4b0080e87c9abcb6fa6c97.css
[...]
AssetSync: Done.
It this normal?
When I precompile to other environments (non-production), I can see the detailed compilation of each asset twice:
~/projects/rewportal(mapwidget ✔) rake RAILS_ENV=qa assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/home/ruy/.rvm/rubies/ruby-1.9.3-p194/bin/ruby /home/ruy/.rvm/gems/ruby-1.9.3-p194#rewportal/bin/rake assets:precompile:all RAILS_ENV=qa 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
AssetSync: using /home/ruy/projects/rewportal/config/initializers/asset_sync.rb
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
Compiled gmaps4rails/gmaps4rails.base.js (141ms) (pid 8480)
Compiled gmaps4rails/gmaps4rails.googlemaps.js (148ms) (pid 8480)
[...]
Compiled active_admin.css (1299ms) (pid 8480)
Compiled active_admin/print.css (113ms) (pid 8480)
** Invoke assets:precompile:nondigest (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
AssetSync: using /home/ruy/projects/rewportal/config/initializers/asset_sync.rb
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:nondigest
Compiled gmaps4rails/gmaps4rails.base.js (133ms) (pid 8480)
Compiled gmaps4rails/gmaps4rails.googlemaps.js (133ms) (pid 8480)
[...]
Compiled active_admin.css (1290ms) (pid 8480)
Compiled active_admin/print.css (116ms) (pid 8480)
AssetSync: Syncing.
Using: Directory Search of /home/ruy/projects/rewportal/public/assets
Uploading: assets/active_admin-d05b61ab8366b74eabc9074d3e60fe82.css.gz
[...]
Fetching files to flag for delete
Flagging 6 file(s) for deletion
Deleting: assets/active_admin-ec90e7d9a9f45f14d1387f58fa1452b4.css
[...]
AssetSync: Done.
My application.rb has the following:
config.assets.precompile += %w( active_admin/print.css active_admin.css active_admin.js admin.js admin.css html5shiv.js )
Ideas?
Rails 3 by default compiles once to generate fingerprinted assets, and once to generate non-fingerprinted assets (the fingerprinted ones have the MD5 hash in the filename).
You can use the turbo-sprockets-rails3 gem to create both from one compilation.
In Rails 4, this functionality was extracted into the sprockets-rails gem and the behavior was changed, so the double compilation does not happen in Rails 4.
Are you using capistrano? If so, you can try to compile your assets locally, and then upload to server, with a task like this
namespace :deploy do
namespace :assets do
desc "Precompile assets on local machine and upload them to the server."
task :precompile, roles: :web, except: {no_release: true} do
run_locally "bundle exec rake assets:precompile"
find_servers_for_task(current_task).each do |server|
run_locally "rsync -vr --exclude='.DS_Store' public/assets #{user}##{server.host}:#{shared_path}/"
end
end
end
end
I overwrite the deploy_all task inside deploy.rb to compile before uploading:
task :remake_all do
puts "precompiling assets"
res = `env rake assets:precompile:all RAILS_ENV=precompile RAILS_GROUPS=assets 2>&1`
$stderr.puts "assets res is: #{res}"
if res =~ /aborted|don't|invalid|segmentation|bug/i
puts "############ Unable to compile assets #########"
exit
end
end
I had issues with the development environment not compiling properly and the production environment needing access to mysql servers behind a firewall, so made a new environment called :precompile
The solution for me (Rails 3) was to run rake assets:precompile:primary instead of rake assets:precompile:all.

Manifest.yml empty

Whenever I run rake assets:precompile, I get a manifest.yml file that looks like:
--- {}
Something must be going wrong. Here is my output for rake assets:precompile --trace:
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/Users/user/.rvm/rubies/ruby-1.9.3-p194/bin/ruby /Users/user/.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 tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
** Invoke assets:precompile:nondigest (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:nondigest
Can someone help?? Thanks!
UPDATE:
Feel free to look at my code at www.github.com/sambaek/novulty
When I run rake assets:precompile for your application I get the following output
➜ novulty git:(master) ✗ rake assets:precompile
/Users/deefour/.rbenv/versions/1.9.3-p125/bin/ruby /Users/deefour/.rbenv/versions/1.9.3-p125/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
Undefined variable: "$baseLineHeight".
(in /Users/deefour/.rbenv/versions/1.9.3-p125/gemsets/novulty/gems/bootstrap-sass-2.1.0.1/vendor/assets/stylesheets/bootstrap/_accordion.scss)
Tasks: TOP => assets:precompile:primary
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/Users/deefour/.rbenv/versions/1.9.3-p125/...]
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
rake assets:precompile 12.50s user 1.21s system 99% cpu 13.744 total
I'm not sure what your intention is, but you have
app/asssets/bootstrap.min.css being included in app/assets/application.css
gem 'bootstrap-sass' in your Gemfile which appears to cause bootstrap-sass-2.1.0.1/vendor/assets/stylesheets/bootstrap/_accordion.scss (among other files) to be added to your pipeline even though they're not included in require lines in app/assets/application.css
It seems like you have the bootstrap gem included to use it's Javascript plugins, but are trying to omit the SASS files in favor of the hard-coded, minified CSS file?
In any event, the error I get says that the $baseLineHeight SASS variable is not defined for a line in that gem file's asset - an asset you otherwise appear to ignore (from the best I can tell).
I then did the following
Commented out the bootstrap-sass gem in your Gemfile
#gem 'bootstrap-sass'
Ran bundle
Ran rake assets:clean
Removed the following require lines from your app/assets/application.js because they were coming from the bootstrap-sass gem I removed in 1. above
//= require bootstrap-transition
//= require bootstrap-button
//= require bootstrap-carousel
//= require bootstrap-collapse
//= require bootstrap-tab
Ran rake assets:precompile
This results in the following public/assets/manifest.yml.
https://gist.github.com/d29f70b047c7b0606263
I think you need to either of the following
Use the bootstrap-sass gem as intended. Include the SASS files in your app/assets/application.css (doing this it a bit outside the scope of this question)
Get rid of the bootstrap-sass gem as I have above, and include the necessary Javascript files as assets in your vendor/assets/javascripts directory (which is where app/assets/stylesheets/bootstrap.min.css belongs too - vendor/assets/stylesheets)

Rake tasks on Rails 3.1.3 - Application already initialized

I'm unable to get rake precompile tasks running with Rails 3.1.3. I get the following error:
$ rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/Users/tristankromer/.rvm/rubies/ruby-1.9.2-p290/bin/ruby /Users/tristankromer/.rvm/gems/ruby-1.9.2-p290#toomanyninjas/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
rake aborted!
Application has been already initialized.
/Users/tristankromer/.rvm/gems/ruby-1.9.2-p290#toomanyninjas/gems/railties-3.1.3/lib/rails/application.rb:95:in `initialize!'
Same thing happens when I used bundle exec or when I deploy to heroku cedar stack.
Not quite sure where to start on this one. Any ideas?
UPDATE: I'm having issues with every rake task:
rake aborted!
Application has been already initialized.
/Users/tristankromer/.rvm/gems/ruby-1.8.7-p249#joke-off/gems/railties-3.1.3/lib/rails/application.rb:95:in `initialize!'
Upgrading rake to 0.9.2.2 and using ruby 1.9.2-p290 seems to have fixed the issue.
I had this issue, I didn't want to upgrade ruby, and what ended up working for me was the renaming config.ru in RAILS_ROOT to config.ru.bak
http://code.google.com/p/phusion-passenger/issues/detail?id=109
I came across this after realizing I was having an issue getting Passenger to recognize the "RailsEnv" setting my my virtual hosts conf
I had this problem on Rails 3.2.6
The reason it was happening had to do with a path linked gem having a bundle folder. in my gemfile
like so:
gem 'some-gem', :path => "vendor/some-gem"
In order to fix the issue I just moved the bundle folder out of the path linked gem.
mv vendor/some-gem/bundle ~
Once the bundle file was gone it worked perfectly

Resources