Sass::SyntaxError: File to import not found or unreadable: bootstrap-sprockets

前端 未结 15 1314
眼角桃花
眼角桃花 2020-11-30 03:40

I am suddenly getting this error in development and in production on deployment.

custom.css.scss

@import \"bootstrap-sprockets\";
@import \"bootstrap         


        
相关标签:
15条回答
  • 2020-11-30 04:20

    Please restart you rails server after every changes in Gemfile

    rails server
    
    0 讨论(0)
  • 2020-11-30 04:22

    I had same problem but i solved it, you just need to add your gem bootstrap-sass in development group like this:

        group :development do
        gem 'bootstrap-sass'
        end
    

    i hope this will help

    0 讨论(0)
  • 2020-11-30 04:23

    In your Gemfile you need to add the bootstrap-sass gem, and ensure that the sass-rails gem is present - it is added to new Rails applications by default.

    gem 'bootstrap-sass', '3.3.7'
    gem 'sass-rails', '5.0.6'
    gem 'rails', '5.0.0'
    

    bundle install and restart your server to make the files available through the pipeline. Import Bootstrap styles in app/assets/stylesheets/application.scss:

    // "bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables"
    @import "bootstrap-sprockets";
    @import "bootstrap";
    

    bootstrap-sprockets must be imported before bootstrap for the icon fonts to work. Make sure the file has .scss extension (or .sass for Sass syntax). If you have just generated a new Rails app, it may come with a .css file instead. If this file exists, it will be served instead of Sass, so rename it:

    $ mv app/assets/stylesheets/application.css TO: app/assets/stylesheets/application.scss

    Then, remove all the *= require_self and *= require_tree . statements from the sass file. Instead, use @import to import Sass files. e.g

    *= require_tree .
    *= require_self
    

    To:

    @import require_tree .
    @import require_self
    

    Do not use *= require in Sass or your other stylesheets will not be able to access the Bootstrap mixins or variables. Bootstrap JavaScript depends on jQuery. If you're using Rails 5.1+, add the jquery-rails gem to your Gemfile:

    gem 'jquery-rails'
    
    $ bundle install
    

    Require Bootstrap Javascripts in

    app/assets/javascripts/application.js:

    //= require jquery
    //= require bootstrap-sprockets
    

    bootstrap-sprockets and bootstrap should not both be included in

    application.js

    . bootstrap-sprockets provides individual Bootstrap Javascript files (alert.js or dropdown.js, for example), while bootstrap provides a concatenated file containing all Bootstrap Javascripts.

    This will fix the error

    Copied @github
    
    0 讨论(0)
提交回复
热议问题