-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
stylesheet_pack_tag
should be consistent about whether it produces error (or not) about missing asset regardless of extract_css
#2342
Comments
For codebases with a moderate amount of styling, Let's continue this in the other issues you opened. |
I just spent a couple of hours trying to figure out why production was failing but development works fine. We added a pack and put in the This being a fatal error in production with no warning during development is very surprising. It is a hard to track down error, especially because webpack just reports the name of the pack without a file extension. We thought something was wrong with the JavaScript and just by trying everything possible found out that it was the stylesheet failing. None of the linked issues from @TylerRick specifically address production having a fatal production error when it can't find a css file. :( Can we reopen this and address it directly? |
Seriously this is a big problem to think your app is running fine, to find out it's not a silent error in production |
it would be nice if there was a stylesheet pack tag helper that included css if it exists, and failed silently if not |
my workaround for anyone looking for a quick fix: # app/helpers/webpacker_overrides.rb
module WebpackerOverrides
private
def rescued_pack_tags
@rescued_pack_tags ||= {}
end
def sources_from_manifest_entries(names, type:)
names.map do |name|
unless (type == :stylesheet) && rescued_pack_tags[name]
current_webpacker_instance.manifest.lookup!(name, type: type)
end
rescue
raise unless type == :stylesheet
rescued_pack_tags[name] = true
nil
end.flatten.select(&:present?)
end
end |
Webpacker has a nasty habit of not compiling css files for components and then causing an error in production when they are missing. rails/webpacker#2342 rails/webpacker#2059 (comment) This adds an override which causes no errors in production but still allows us to leave the stylesheet_pack_tag for when it is needed.
Webpacker has a nasty habit of not compiling css files for components and then causing an error in production when they are missing. rails/webpacker#2342 rails/webpacker#2059 (comment) This adds an override which causes no errors in production but still allows us to leave the stylesheet_pack_tag for when it is needed.
This issue should really be reopened since this seems to be the only issue that was created by @TylerRick specifically about the inconsistent behavior of |
Webpacker has a nasty habit of not compiling css files for components and then causing an error in production when they are missing. rails/webpacker#2342 rails/webpacker#2059 (comment) Unfortunately using extract_css: true all the time apparently comes with some performance impacts, however the tradeoff is the application actually works correctly in development mode.
Webpacker has a nasty habit of not compiling css files for components and then causing an error in production when they are missing. rails/webpacker#2342 rails/webpacker#2059 (comment) Unfortunately using extract_css: true all the time apparently comes with some performance impacts, however the tradeoff is the application actually works correctly in development mode.
Would it be okay if we either:
make
stylesheet_pack_tag
always simply silently return nil if there is no stylesheet for the given pack name (this is currently the behavior only ifextract_css: false
), ormake
stylesheet_pack_tag
always raise aWebpacker can't find {pack_name} in public/packs/manifest.json
Webpacker::Manifest::MissingEntryError
if there is no stylesheet for the given pack name (this is currently the behavior only ifextract_css: true
)?
Documentation reference
My workaround
I ended up not running into an error from a
stylesheet_pack_tag
referencing something that wasn't in the manifest until it got to staging. It bugged me that development behaves differently from production. Enough that I changed thedefault:
section of myconfig/webpacker.yml
to:I'm not sure yet if there are any downsides to using
extract_css: true
in development (no HMR?), but at least this gives me the same behavior between dev and production...Confusion in the community
#2059 (comment)
#2059 (comment)
#2202:
The text was updated successfully, but these errors were encountered: