Closed (duplicate)
Project:
Drupal core
Version:
8.9.x-dev
Component:
asset library system
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
5 Jan 2021 at 13:09 UTC
Updated:
23 Jan 2021 at 21:09 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
je1 commentedRunning multisite on one installation. Some of the sites show this error and some don't, is there a way to clean up optimized on sites that show this error to force it to re-optimize CSS?
PHP 7.3.16
Server version: Apache/2.4.6 (CentOS)
CentOS Linux release 7.7.1908 (Core)
Comment #3
cilefen commentedComment #4
larowlanIs it possible one of your library.yml files inadvertently lists a non CSS file, eg a sass, pcss or js file instead
Can you debug which file causes the notice
Comment #5
je1 commentedsearched for sass, pcss, and js. found only one
/var/www/drupal$ find *library.yml | xargs grep -i js
./core/modules/media_library/config/install/views.view.media_library.yml: row_class: 'media-library-item media-library-item--table js-media-library-item js-click-to-select'
Comment #6
larowlanDo you have any custom themes or modules on this site?
This error occurs if you attempt to optimize a css entry from a libraries.yml where the css entry is e.g. a URI and not a file
Comment #7
je1 commentedWe use theme gavias_tico and there is file called gavias_tico.libraries.yml
Comment #8
larowlanDo you get the same issue with a different theme?
That theme isn't available on Drupal.org, so I assume is custom.
The issue is likely in the libraries file in that theme.
Comment #9
je1 commentedWe use the same theme for multiple website subdomains, the exception shows up on two of them but not the others. Have not tried using other theme to check.
The exception log messages show different pages url locations
Exception: Only file CSS assets can be optimized. in Drupal\Core\Asset\CssOptimizer->optimize() (line 25 of /var/www/drupal/core/lib/Drupal/Core/Asset/CssOptimizer.php).
Comment #10
je1 commentedComment #11
larowlanTry adding `preprocess: false` to the Google font entries
Comment #12
je1 commentedLike this?
css:
theme:
//fonts.googleapis.com/css?family=Raleway:400,600,700,800,900: { type: external, preprocess: false }
//fonts.googleapis.com/css?family=Open+Sans:400,600,700,800: { type: external, preprocess: false }
Comment #13
larowlanYeah
Comment #14
je1 commentedThat didn't fix it.
Comment #15
je1 commentedBefore the exception, there are about 10 notices like this one:
Notice: Undefined index: type in Drupal\Core\Asset\CssOptimizer->optimize() (line 24 of /var/www/drupal/core/lib/Drupal/Core/Asset/CssOptimizer.php)
#0 /var/www/drupal/core/includes/bootstrap.inc(600): _drupal_error_handler_real(8, 'Undefined index...', '/var/www/drupal...', 24, Array)
Comment #16
je1 commentedAnd 2 warnings like this:
Warning: ksort() expects parameter 1 to be array, null given in Drupal\advagg_bundler\Asset\AdvaggCssCollectionGrouper->group() (line 62 of /var/www/drupal/modules/advagg/advagg_bundler/src/Asset/AdvaggCssCollectionGrouper.php)
#0 /var/www/drupal/core/includes/bootstrap.inc(600): _drupal_error_handler_real(2, 'ksort() expects...', '/var/www/drupal...', 62, Array)
#1 [internal function]: _drupal_error_handler(2, 'ksort() expects...', '/var/www/drupal...', 62, Array)
Comment #17
larowlanDoes this occur if adv_agg is turned off
Comment #18
je1 commentedNotice: Undefined index: weight in Drupal\Core\Asset\AssetResolver::sort() (line 386 of /var/www/drupal/core/lib/Drupal/Core/Asset/AssetResolver.php)
#0 /var/www/drupal/core/includes/bootstrap.inc(600): _drupal_error_handler_real(8, 'Undefined index...', '/var/www/drupal...', 386, Array)
#1 /var/www/drupal/core/lib/Drupal/Core/Asset/AssetResolver.php(386): _drupal_error_handler(8, 'Undefined index...', '/var/www/drupal...', 386, Array)
Comment #19
je1 commentedJust to make sure, you mean to uncheck "Enable advanced aggregation"
Administration > Configuration > Development > Performance
Comment #20
larowlanYes, sorry
Comment #21
je1 commentedThat didn't fix it.
Comment #22
je1 commentedJust food for thought
Is there a way to clear CSS Optimizer data or all optimized data and force it to start the optimize process from the beginning?
or may be add logger line of code in the optimizer to tell us where it is coming from?
Comment #23
je1 commentedwebsite shows
The website encountered an unexpected error. Please try again later.
Comment #24
je1 commentedTo reproduce on production site,
Fill contact us form and submit or login as admin. After that the contact form and login will show "Try again ..." until drush -cr
Any ideas?
Comment #25
cilefen commented@je1 Is that starting from "Install Drupal"? Because much of Drupal core has test coverage I think there is something else we would need to reproduce the issue.
Comment #26
je1 commentedThanks for the help,
Yes, that is started with first install of drupal 8.
Attached is enabled modules list
Comment #27
cilefen commentedIs it #3169757: WSOD and Uncaught PHP Exception Exception: "Only file CSS assets can be optimized."? How much have you searched around about this?
Comment #28
je1 commentedIt is not that one, tried disabling css injector preprocessing like it says last week and that didn't fix it.
Started seeing this error after moving from D7 to D8 last year and thought it will go away once D8 gets updated with fixes.
We have one website sub-domain running on same code base and configuration, it doesn't show that error. May be something in database or some files under file system folder /files that causing it, like gz files under css/js but don't know much about how the optimizer works. All these files have recent dates though.
Disabled cron tasks and that didn't fix it.
Researched but there is not much found other than #3169757 and few other comments.
Comment #29
cilefen commentedHave you tried adding logging to reveal which asset causes this?
Comment #30
je1 commentedYou mean to change line 25 of /var/www/drupal-8.9.11/core/lib/Drupal/Core/Asset/CssOptimizer.php
public function optimize(array $css_asset) {
if ($css_asset['type'] != 'file') {
throw new \Exception('Only file CSS assets can be optimized.');
}
to
public function optimize(array $css_asset) {
if ($css_asset['type'] != 'file') {
\Drupal::logger('module')->notice($css_asset);
throw new \Exception('Only file CSS assets can be optimized.');
}
Will that work? not sure what module, or you have better lines of code to add?
Comment #31
cilefen commentedYes. But careful: $css_asset is an array so you'll have to pass something like
print_r($css_asset, TRUE)to ->notice(). Use something more unique for the 'module' string so you will notice this. Perhaps raise the log level above notice.Comment #32
je1 commentedHere is the $css_asset array
Array ( [group] => 999 [browsers] => )
Comment #33
je1 commentedComment #34
cilefen commentedAs I suspected above, this is very likely Asset Injector module so this will be a duplicate of #3169757: WSOD and Uncaught PHP Exception Exception: "Only file CSS assets can be optimized.".
Comment #35
je1 commentedWe disabled the CSS preprocessing for Asset Injector and it didn't fix it.
Configuration -> Development -> Asset Injector -> Css Injector and unselected Preprocess CSS
Did we miss something from #3169757 fix?
Comment #36
cilefen commented#3169757: WSOD and Uncaught PHP Exception Exception: "Only file CSS assets can be optimized." would be the place to talk about that. All this is on the assumption that the "999" group is from that module. You could search your codebase for 999 in case it is elsewhere.
Comment #37
je1 commentedAttached is the 999 that I can find in the code base, removed the strings other than just 999.
Not sure, is that what we looking for?
./modules/asset_injector/src/Form/AssetInjectorFormBase.php: '#weight' => 999,
Comment #38
cilefen commentedIf this were my codebase I would consider this identified. I'm marking this as a duplicate.
Comment #39
je1 commentedI searched only the *.php and *.inc files, should I search all files or that is enough?
Comment #40
je1 commentedUninstalling the module (Asset Injector) resolved this issue.