Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
TangMonk opened this issue Oct 16, 2022 · 2 comments

Comments

@TangMonk
Copy link

image

@ychaker
Copy link

ychaker commented Nov 17, 2022

@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
Copy link

ansonhoyt commented Oct 19, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants