twbs/bootstrap-rubygem

Rails7 Error: File to import not found or unreadable: bootstrap/scss/bootstrap.

TangMonk opened this issue · 3 comments

@TangMonk I'm pretty sure you only need to use @import "bootstrap"; to load all of the files or @import "bootstrap/variables";` to load a specific partial.

@TangMonk I doubt this is a bug with this gem, so can this be closed?

I agree@import "bootstrap" should work, but I might be able to help...

You haven't given much detail, but perhaps you're using sprockets-rails for styles with jsbundling-rails for javascript? You may have installed the bootstrap nvm package to get Bootstrap's javascript, and are trying load that bootstrap.scss from Sprockets.

If so, I've seen this error, since doing that requires appending to the default asset search paths for Sprockets to look in ./node_modules:

# config/initializers/assets.rb
+ Rails.application.config.assets.paths << Rails.root.join('node_modules')
// app/assets/stylesheets/application.bootstrap.scss loaded with sprockets-rails
@import 'bootstrap/scss/bootstrap';

Should now work because Sprockets can now find this file:

$ file node_modules/bootstrap/scss/bootstrap.scss # sprockets adds the .scss extension for you
node_modules/bootstrap/scss/bootstrap.scss: ASCII text

The JavaScript would already be loading fine with jsbundling-rails, because it already looks in node_modules out of the box:

// app/javascript/application.js loaded with js-bundling-rails
import * as bootstrap from 'bootstrap'