twbs / bootstrap-sass

Official Sass port of Bootstrap 2 and 3.
http://getbootstrap.com/css/#sass
MIT License
12.59k stars 3.53k forks source link

Rails 5.1.7: The asset "../fonts/bootstrap/glyphicons-halflings-regular.eot" is not present in the asset pipeline #1207

Open etagwerker opened 4 years ago

etagwerker commented 4 years ago

Hi there,

I'm running into an issue with bootstrap-sass:

2019-12-13T20:55:05.381913+00:00 app[web.1]: I, [2019-12-13T20:55:05.381834 #4]  INFO -- : [bbb3f58f-44fe-49f5-86f3-fd7c9dd14f88] Completed 500 Internal Server Error in 161ms (ActiveRecord: 6.9ms)
2019-12-13T20:55:05.382517+00:00 app[web.1]: F, [2019-12-13T20:55:05.382413 #4] FATAL -- : [bbb3f58f-44fe-49f5-86f3-fd7c9dd14f88]
2019-12-13T20:55:05.382562+00:00 app[web.1]: F, [2019-12-13T20:55:05.382513 #4] FATAL -- : [bbb3f58f-44fe-49f5-86f3-fd7c9dd14f88] ActionView::Template::Error (The asset "../fonts/bootstrap/glyphicons-halflings-regular.eot" is not present in the asset pipeline.):
2019-12-13T20:55:05.382717+00:00 app[web.1]: F, [2019-12-13T20:55:05.382652 #4] FATAL -- : [bbb3f58f-44fe-49f5-86f3-fd7c9dd14f88]     2: <html>

It seems that the URL is not Rails 5.1.7 friendly.

I think that a search and replace change in the paths might be necessary.

Thanks, Ernesto

StefanWallin commented 4 years ago

I concur but I think this is not a problem in a specific Rails version, rather a version of sprockets. I took this up on the sprockets-rails repo and they decided that this is a bootstrap-sass issue for not using the sprockets-4.0.0 api correctly. Sprockets has since version 4 stopped supporting regular expressions in asset paths.

This was my bug report to sprockets-rails and for that I've set up a reproduction case example app: https://github.com/rails/sprockets-rails/issues/457

I've tried my best to try and make a PR, but all the ways I could fathom to try have failed me, relative paths, absolute paths, adding directory to config.assets.path or adding file paths to config.assets.precompile and variants of that.

Right now I'm adding absolute file paths to config.assets.precompile which make sprockets deal with the files but then I get stuck on the following error instead:

Sprockets::ConversionError: could not convert "application/x-font-ttf" to nil whenever I try to run bundle exec rake assets:precompile --trace

My engine.rb looks like this:

module Bootstrap
  module Rails
    class Engine < ::Rails::Engine
        ...
        sprockets_version = Sprockets::Rails::VERSION.split('.', 2)[0].to_i
        unless sprockets_version == 3
        ...
        end

        unless sprockets_version == 4
          # sprockets-rails 4 no longer support regexes for asset paths
          fileendings = %w(svg ttf woff woff2)
          fileendings.each do |fileending|
            path = root.join("assets/fonts/glyphicons-halflings-regular.#{fileending}").to_s
            uri = "file://#{path}"
            app.config.assets.precompile << [uri]
          end
        end
      end
    end
  end
end
Geesu commented 4 years ago

Did you find a solution to this? We're running into the same issue on rails 5.2 w/sprockets 4.

timdiggins commented 1 year ago

I've had no problem running rails 5.2 and sprockets 4 for a while, and think this should be closed.

FYI I got here because I thought there was a sprockets 4 problem with rails 6.0 somehow (on upgrade) and investigated https://github.com/rails/sprockets-rails/issues/457 but I think that the response (https://github.com/rails/sprockets-rails/issues/457#issuecomment-575249175) was a misreading of the code (reading the sprockets < 3 targeted code as if it applied to sprockets 4).

When I debugged my situation (an error on CI) I found it was because I was issuing the precompile with different flags from issuing the test code -- ie. one was effectively using RAILS_ENV=development, resulting in (in my configuration) config.assets.digest=false but the rspec run was resulting in config.assets.digest=true (and I had config.assets.unknown_asset_fallback = false, resulting in the error).

A similar situation would happen if you (somehow) precompile without digests and then run your server with them (but with config.assets.compile=false)

Faq commented 1 year ago

As @StefanWallin linked, problem with sprockets 4, changed path handling, therefore need to help this old gem to find his fonts. So what I did is override that @import "bootstrap_sprockets" by making new file in overrides folder bootstrap_sprockets.scss, with content:

@function twbs-font-path($path) {
  @return $path;
}

@function twbs-image-path($path) {
  @return image-path($path);
}

$bootstrap-sass-asset-helper: true;
$icon-font-path: "bootstrap/";

Using this option Where in application.scss file links that file with @import "bootstrap-custom";

Content of "bootstrap-custom.scss":

@import "../overrides/bootstrap_sprockets";

// Core variables and mixins
@import "bootstrap/variables";
@import "bootstrap/mixins";

// Reset and dependencies
@import "bootstrap/normalize";
@import "bootstrap/print";
@import "bootstrap/glyphicons";

// Core CSS
@import "bootstrap/scaffolding";
@import "bootstrap/type";
@import "bootstrap/code";
@import "bootstrap/grid";
@import "bootstrap/tables";
@import "bootstrap/forms";
@import "bootstrap/buttons";

// Components
@import "bootstrap/component-animations";
@import "bootstrap/dropdowns";
@import "bootstrap/button-groups";
@import "bootstrap/input-groups";
@import "bootstrap/navs";
@import "bootstrap/navbar";
@import "bootstrap/breadcrumbs";
@import "bootstrap/pagination";
@import "bootstrap/pager";
@import "bootstrap/labels";
@import "bootstrap/badges";
@import "bootstrap/jumbotron";
@import "bootstrap/thumbnails";
@import "bootstrap/alerts";
@import "bootstrap/progress-bars";
@import "bootstrap/media";
@import "bootstrap/list-group";
@import "bootstrap/panels";
@import "bootstrap/responsive-embed";
@import "bootstrap/wells";
@import "bootstrap/close";

// Components w/ JavaScript
@import "bootstrap/modals";
@import "bootstrap/tooltip";
@import "bootstrap/carousel";

// Utility classes
@import "bootstrap/utilities";
@import "bootstrap/responsive-utilities";

or just:

@import "../overrides/bootstrap_sprockets";
@import "bootstrap";
timdiggins commented 1 year ago

@Faq @StefanWallin I'm unconvinced that sprockets 4 + bootstrap-sass is the root problem here.

I just fixed the minimal reproduction repo's issue (thanks for creating this @StefanWallin !) by adding in @import "bootstrap-sprockets" before importing bootstrap itself and there's no issue. https://github.com/timdiggins/sprockets-test-app/commit/a72c41bcfc0eccb9d258b7444dd062de675043e8

Here's a screenshot (but do see what happens locally if you want to -- Haven't written a test for this because life is too short 😁 ):

SprocketsTestApp

I just think it's worth documenting what we know can work, because then we can look for the problems elsewhere.