Problem/Motivation
I have just update the website from latest D8 to D9.4.7 and now I am getting bunch of errors in console. Website loads fine but it looks like jquery once library is not loaded at all.
As far as I understand, jquery.once was removed in 9.3, but also it looks like bunch of core files depend on this library.
Uncaught TypeError: once is not a function
at Object.attach (contextual.js?v=9.4.7:102:29)
at drupal.js?v=9.4.7:27:24
at Array.forEach (<anonymous>)
at Drupal.attachBehaviors (drupal.js?v=9.4.7:24:34)
at drupal.init.js?v=9.4.7:29:12
at HTMLDocument.listener (drupal.init.js?v=9.4.7:17:7)
Uncaught TypeError: once is not a function
at Drupal.ajax.bindAjaxLinks (ajax.js?v=9.4.7:142:5)
at Object.attach (ajax.js?v=9.4.7:42:19)
at drupal.js?v=9.4.7:27:24
at Array.forEach (<anonymous>)
at Drupal.attachBehaviors (drupal.js?v=9.4.7:24:34)
at drupal.init.js?v=9.4.7:29:12
at HTMLDocument.listener (drupal.init.js?v=9.4.7:17:7)
Uncaught TypeError: once is not a function
at Object.attach (toolbar.js?v=9.4.7:27:7)
at drupal.js?v=9.4.7:27:24
at Array.forEach (<anonymous>)
at Drupal.attachBehaviors (drupal.js?v=9.4.7:24:34)
at drupal.init.js?v=9.4.7:29:12
at HTMLDocument.listener (drupal.init.js?v=9.4.7:17:7)
... etc.
The same errors goes for: tour.js?v=9.4.7:12:7, contextual.toolbar.js?v=9.4.7:37:11, escapeAdmin.js?v=9.4.7:19:27, big_pipe.js?v=9.4.7:50:5
When I click on those files, all are located in in core/modules and all are using syntax like once(something). I am not sure whether this is due to my upgrade or not.
I tried adding core/once as library dependency on my theme file but it had no effect, I guess theme files are loaded way after core modules but also I do not know how to solve that. I tried also adding this code to my module:
/**
* Implements hook_library_info_alter().
*/
function MYMODULE_library_info_alter(&$libraries, $extension) {
foreach ($libraries as &$library) {
if (!in_array('core/jquery.once', $library['dependencies'] ?? [])) {
continue;
}
$dependencies = array_filter($library['dependencies'] ?? [], function ($item) {
return $item != 'core/jquery.once';
});
$dependencies[] = 'core/once';
$dependencies[] = 'core/jquery.once.bc';
$library['dependencies'] = $dependencies;
}
}
But it unfortunately also had no effect. It looks like apart from that upgrade all went smooth so this is the only thing bothering me now.