rails / propshaft

Deliver assets for Rails
MIT License
864 stars 93 forks source link

Builds folder not appearing in asset load path causing 'home.css' asset not found error #186

Closed mario-amazing closed 4 months ago

mario-amazing commented 4 months ago

I encountered an issue where the builds folder is not being recognized in the asset load path, resulting in an error stating that the asset 'home.css' cannot be found. This issue is causing a failure in rendering the home page due to the missing stylesheet.

Error:

ActionView::Template::Error (The asset 'home.css' was not found in the load path.):
    10:     <%= csrf_meta_tags %>
    11:     <%= csp_meta_tag %>
    12:
    13:     <%= stylesheet_link_tag "home" %>
    14:     <%= javascript_include_tag "home_main", type: "module" %>
    15:   </head>
    16:

app/views/layouts/home.html.erb:13
Error during failsafe response: The asset 'home.css' was not found in the load path.
  /app/vendor/bundle/ruby/3.3.0/gems/propshaft-0.8.0/lib/propshaft/helper.rb:4:in `compute_asset_path'
bin/rake assets:reveal:full
/app/app/assets/builds/home.css
...
ls /app/app/assets/builds/
home.css             home_main.js         home_main.js.map ...
# Error here:
module Propshaft
2 | module Helper
3 | def compute_asset_path(path, options = {})
4 | Rails.application.assets.resolver.resolve(path) || raise(MissingAssetError.new(path))
5 | end
Loading production environment (Rails 7.1.3.2)
[1] pry(main)> Rails.application.assets.load_path.find('home.css').present?
=> true
[2] pry(main)> Rails.application.assets.resolver.resolve('home.css')
=> nil

Build:

{
   ...,
  "scripts": {
    "build": "esbuild app/javascript/*.* --bundle --sourcemap --format=esm --outdir=app/assets/builds --public-path=/assets",
    "build:css": "yarn build:css:compile && yarn build:css:prefix",
    "build:css:compile": "sass ./app/assets/stylesheets/home.scss:./app/assets/builds/home.css ./app/assets/stylesheets/active_admin.scss:./app/assets/builds/active_admin.css --no-source-map --load-path=node_modules",
    "build:css:prefix": "postcss ./app/assets/builds/home.css --use=autoprefixer --output=./app/assets/builds/home.css",
    "watch:css": "nodemon --watch ./app/assets/stylesheets/ --ext scss --exec \"yarn build:css\""
  },
}

How can I fix it in production?

dhh commented 4 months ago

Do you have app/assets/builds/.keep checked in? So that the path is added before it's being resolved?

mario-amazing commented 4 months ago

@dhh, thanks a lot, adding the app/assets/builds/.keep helped

dhh commented 4 months ago

We should ensure that css/jsbundling-rails does this, if they don't already. Please do take a look and open an issue on those if that's not the case. Thanks!