twbs / bootstrap-rubygem

Bootstrap rubygem for Rails / Sprockets / Hanami / etc
https://rubygems.org/gems/bootstrap
MIT License
2.01k stars 451 forks source link

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

Open TangMonk opened 1 year ago

TangMonk commented 1 year ago
image
ychaker commented 1 year ago

@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.

ansonhoyt commented 10 months ago

@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'
maxgronlund commented 2 months ago

Hi @TangMonk,

I'm working on an open-source project and have been encountering similar issues while trying to integrate this engine: LoggableActivity, into this application: LoggableActivityDemoApp.

I keep getting this error: Error: File to import not found or unreadable: bootstrap/functions.

There's a link to a Slack channel for the project on this page: Loggable Activity Slack Channel.