Rails: File to import not found or unreadable: “bootstrap”

前端 未结 8 1299
野的像风
野的像风 2021-02-19 14:03

I am relatively new to programming, therefore I hope that the question is not absolutely stupid.

I got a problem concerning my rails app.

I try to use bootstrap.

8条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-19 14:28

    I had a similar issue when working on a Rails 6 application with Bootstrap 4.

    The issue was that I did not specify the node modules full path of the bootstrap.scss file in my app/assets/stylesheets/application.scss file.

    After installing Bootstrap 4 and its dependencies using this command:

    yarn add bootstrap jquery popper.js
    

    All I needed to do was to modify it from:

    @import "bootstrap";
    

    to

    @import 'bootstrap/scss/bootstrap';
    

    You can then add require the boostrap.js file in the app/javascript/packs/application.js file this way:

    require("bootstrap");
    

    That's all.

    I hope this helps

提交回复
热议问题