2

My app works locally; however, when I try to deploy it to Heroku I get the following error:

remote:        Sass::SyntaxError: File to import not found or unreadable: bootstrap/dist/css/bootstrap.
remote:        (sass):18
.....
remote:        /tmp/build_c0c6ec9ea8e1ea183aca6e660993c246/vendor/bundle/ruby/2.2.0/gems/sprockets-rails-3.0.1/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
remote:        
Sass::SyntaxError: File to import not found or unreadable: bootstrap/dist/css/bootstrap.
.....
remote:        Tasks: TOP => assets:precompile
remote:        (See full trace by running task with --trace)
remote:  !
remote:  !     Precompiling assets failed.
remote:  !

Here are the application.scss, and Gemfile files in order:

application.scss:

 *= require_self
 *= require custom
 *= require template
 */
 @import "bootstrap-sprockets";
 @import "bootstrap";

Gemfile:

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.3'
# Specify Rake version
gem 'rake'
# Use postgresql as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use bootstrap sass?
gem 'bootstrap-sass', '>= 3.3.6'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# For user authentication and registration
gem 'devise'

# Font Awesome and simple form
gem 'simple_form'

# For static pages
gem 'high_voltage'

gem 'paperclip', '~> 3.5.3' # github: 'thoughtbot/paperclip

gem 'closure_tree'

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'

  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  gem 'rspec-rails'
  gem 'capybara'
  gem 'launchy'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

and my vendor/assets folder looks like this: enter image description here

UPDATE - changes made to my application.scss are not being pushed up to Heroku. I assume this because even when I take out all the requires and imports, the Heroku precompile still seems to be looking for (and not finding) bootstrap !

Any help is appreciated - let me know if I have missed out anything!

Thanks in advance.

Jay M
  • 259
  • 3
  • 15

3 Answers3

2
  1. You need to import the bootstrap file like this in application.scss:

    @import "bootstrap-sprockets";
    @import "bootstrap";
    
  2. Then, remove all the *= require_self and *= require_tree . statements from the sass file. Instead, use @import to import Sass files.

    Do not use *= require in Sass or your other stylesheets will not be able to access the Bootstrap mixins or variables. See the sass-rails gem documentation for more information on this.

  3. Run $ rake assets:precompile

  4. Run $ git add --all

  5. Run $ git commit -m 'switched to import syntax'

  6. Run $ git push heroku master

Andrew Hendrie
  • 6,205
  • 4
  • 40
  • 71
  • thanks Andrew.. In making those changes, I realised that I also had installed bootstrap through Bower, so I got rid of that. Now I see that none of my changes are being picked up because everytime I try to push to Heroku, I get the same error message. It still looks for bootstrap in vendor/assets, even though it doesn't exist AND it does the same even if I delete all the imports/requires from my application.scss.. any idea what I could be missing out here? – Jay M Feb 09 '16 at 19:35
  • you need to remove the require statements and switch over to using @import for stylesheets. see edit to answer – Andrew Hendrie Feb 09 '16 at 21:26
  • I made those changes too. Looks a lot cleaner and still working locally, but I'm getting EXACTLY the same error message. Could you think of any reason why my changes wouldn't be getting sent up to heroku? – Jay M Feb 10 '16 at 02:50
  • see edit: added another step (number 4) maybe the new files were not staged properly – Andrew Hendrie Feb 10 '16 at 02:54
1

I remember this error back when I used to work on ROR. The issue has to do with the production.rb file inside your config folder.

Make sure this line is made true.

config.assets.initialize_on_precompile = true

Rails comes bundled with a task to compile the asset manifests and other files in the pipeline.

Compiled assets are written to the location specified in config.assets.prefix. By default, this is the /assets directory.

Nikhil Nanjappa
  • 6,454
  • 3
  • 28
  • 44
  • I made the change but the error is the same. I also read that this is no longer necessary in Rails 4. I have a feeling it's something really simple but I just can't place my finger on it. Maybe it is to do with versions of some of the gems I have.. I don't know!.. Thanks – Jay M Feb 08 '16 at 20:48
  • You need to precompile the assets locally and commit them too. [This thread](http://stackoverflow.com/questions/19650621/heroku-upload-precompiling-assets-failed) will be very useful to you. – Nikhil Nanjappa Feb 09 '16 at 05:39
  • I have tried this, and also done what Andrew said. I even uninstalled the bootstrap module I had installed through Bower (app still works because I also had bootstap-sass and sass-rails installed). However, the error message is still the same. It is actually still looking for bootstrap in vendor/assets, even though there is nothing there, and I am not asking it to look there, anywhere in my project. It seems like these changes are not being picked up. And yep, I am adding and commiting the files to git! – Jay M Feb 09 '16 at 19:29
-1

The issue was that I was making changes while on the develop branch and trying to push them, not realising that (NEWBIES TAKE NOTE) when you do git push heroku master it actually only ever pushes from your local master branch.

So I merged all my changes into my master branch and pushed. Problem solved.

If your setup is similar to mine please take note of the other answers because I am sure taking on those suggestions means I avoided some other errors in my code.

Jay M
  • 259
  • 3
  • 15
  • 3
    If for some weird reason you are working off a non-master branch and need to push to heroku, you can also do `git push heroku current-branch-name:master` which will treat the current-branch-name as though it were master for the current push. – Omnilord Feb 24 '17 at 10:32