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

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

Closed
mario-amazing opened this issue Apr 25, 2024 · 3 comments

Comments

@mario-amazing
Copy link

mario-amazing commented Apr 25, 2024

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

dhh commented May 15, 2024

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

@mario-amazing
Copy link
Author

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

@dhh
Copy link
Member

dhh commented May 16, 2024

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!

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

2 participants