简体   繁体   中英

File to import not found or unreadable: bootstrap (Bootstrap, Rails, Sass error)

This is my application.css.scss

/*
 *= require_self
 *= require_tree .
 *= require social-share-button
 */

I am using this gem - https://github.com/twbs/bootstrap-sass

Per the instructions, this is my :assets group in my Gemfile:

group :assets do
  gem 'sass-rails', '~> 4.0.3'
  gem 'uglifier', '>= 1.3.0'
  gem 'coffee-rails', '~> 4.0.0'
  gem "font-awesome-rails"
  gem 'bootstrap-sass', '~> 3.2.0'
  gem 'autoprefixer-rails'
end

I created a file called bootstrap_and_overrides.css.scss , which has this:

@import "bootstrap-sprockets";
@import "bootstrap";
@import "bootstrap-responsive";
@import "font-awesome";

This is the error:

Sass::SyntaxError at /
File to import not found or unreadable: bootstrap-sprockets.
/app/assets/stylesheets/bootstrap_and_overrides.css.scss:1)

This is my application.js :

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require bootstrap-sprockets
//= require social-share-button
//= require_tree .

I have restarted my server many times, and viewed my app from an Incognito window.

I am using Rails 4.1.1 and Ruby 2.1.1.

Any suggestions?

Update 1:

For what it's worth, this is what my app/assets/stylesheets/ looks like:

$ ls
application.css.scss            bootstrap.css               font-awesome.min.css
bootstrap-social.css            bootstrap.min.css           locations.css.scss
bootstrap-theme.css         bootstrap_and_overrides.css.scss    main.css
bootstrap-theme.min.css         font-awesome.css            posts.css.scss

I figured out the issue here.

The problem is I am using an :assets group. That was removed in Rails 4.

http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-3-2-to-rails-4-0-gemfile

**4.2 Gemfile**
Rails 4.0 removed the assets group from Gemfile. You'd need to remove that line from your Gemfile when upgrading. 

Once I pulled them out of the assets group, deleted my Gemfile.lock and ran bundle install ...everything worked perfectly.

Hope this helps some other poor soul.

I just experienced the same problem

File to import not found or unreadable: bootstrap-sprockets

I tried restarting the development server and running "rails s" again and it worked fine!

I had a similar problem but what fixed it for me was:

  • Kill rails server
  • Add instruction gem 'bootstrap-sass', '3.3.6' into my Gemfile
  • Run the bundle install command at the server terminal
  • Restart rails server

However, just to note that I am using the latest version of rails - Rails 5.0.1 so unlike version 4.2, I didn't have to worry about removing the asset do instruction within the Gemfile

这对我有用

gem 'bootstrap-sass', :git => 'https://github.com/twbs/bootstrap-sass.git', :branch => 'next'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM