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

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

Open
etagwerker opened this issue Dec 13, 2019 · 5 comments

Comments

@etagwerker
Copy link

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

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:
rails/sprockets-rails#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
Copy link

Geesu commented Mar 9, 2020

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

@timdiggins
Copy link

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 rails/sprockets-rails#457 but I think that the response (rails/sprockets-rails#457 (comment)) 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
Copy link

Faq commented Nov 2, 2022

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

@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. timdiggins/sprockets-test-app@a72c41b

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.

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

5 participants