Opened 7 months ago
Closed 7 months ago
#64342 closed defect (bug) (wontfix)
wp_enqueue_script_module stopped working on 6.9
| Reported by: | intdef | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Script Loader | Version: | 6.9 |
| Severity: | normal | Keywords: | close |
| Cc: | Focuses: | javascript |
Description
The use of “wp_enqueue_script_module” no longer works. Despite adding arguments (args) to match the example provided in the patch note.
Change History (8)
#2
@
7 months ago
The theme used is Divi (Child theme).
Here is the declaration in my function.php file :
wp_register_script_module('swiper', 'https://cdn.jsdelivr.net/npm/swiper@12/swiper-bundle.min.mjs', array('jquery'), null, array());
// The core GSAP library
wp_register_script_module( 'gsap', 'https://cdn.jsdelivr.net/npm/gsap@3.13.0/+esm', array(), null, array());
// ScrollTrigger - with gsap.js passed as a dependency
wp_register_script_module( 'gsap/ScrollTrigger', 'https://cdn.jsdelivr.net/npm/gsap@3.13.0/dist/ScrollTrigger.min.js/+esm', array('gsap'), null, array() );
wp_register_script_module( 'gsap-stext', 'https://cdn.jsdelivr.net/npm/gsap@3.13.0/dist/SplitText.min.js/+esm', array('gsap'), null, array() );
wp_register_script_module( 'gsap/Flip', 'https://cdn.jsdelivr.net/npm/gsap@3.13.0/dist/Flip.min.js/+esm', array('gsap'), null, array() );
wp_register_script_module('@barba/core', "https://cdn.jsdelivr.net/npm/@barba/core@2.9.7/dist/barba.mjs", array(), null, array());
wp_register_script_module('theme-core', get_stylesheet_directory_uri() . '/assets/js/theme-core.js', array(), null, array());
$dependencies = array(
[
'id' => '@barba/core',
], [
'id' => 'gsap',
'import' => 'static',
], [
'id' => 'gsap/ScrollTrigger',
'import' => 'dynamic',
], [
'id' => 'gsap/Flip',
'import' => 'dynamic',
], [
'id' => 'theme-core',
'import' => 'dynamic',
],[
'id' => 'swiper',
'import' => 'dynamic',
]
);
wp_enqueue_script_module( 'numaa-script', get_stylesheet_directory_uri() . '/assets/js/main.js', $dependencies, 1.0, array(
'fetchpriority' => 'low',
) );
The file that is not loaded is numaa-script. Note that dependencies are loaded in the page. The import map is also loaded.
#3
@
7 months ago
There is the plugin list:
acf-openstreetmap-field
advanced-custom-fields-font-awesome
advanced-custom-fields-pro
contact-form-7
custom-post-type-ui
df-starter(custom plugin)
loginpress
password-protected
popup-maker
seo-by-rank-math
updraftplus
user-switching
#4
follow-up:
↓ 5
@
7 months ago
@intdef thank you. It's my understanding that script modules can't rely on classic scripts like jQuery, which you have as a dependency on swiper. See the Limitations section here: https://make.wordpress.org/core/2024/03/04/script-modules-in-6-5/
Which version of WP were you using before upgrading to 6.9?
#5
in reply to: ↑ 4
@
7 months ago
- Keywords close added
Replying to mindctrl:
It's my understanding that script modules can't rely on classic scripts like jQuery, which you have as a dependency on
swiper. See the Limitations section here: https://make.wordpress.org/core/2024/03/04/script-modules-in-6-5/
This is correct. The jquery dependency is not a script module but rather a classic script, so it is a missing dependency.
In #60647 there was an idea to allow script modules to be able to depend on scripts, but this didn't end up shipping (although the ticket title seems to not have been updated to reflect what ended up landing, cc @jonsurrell). There is a converse ticket for allowing scripts to depend on script modules in #61500.
In any case, it is in fact the case that with 6.9, the behavior of script modules changed so that they will not print if there is any unregistered dependency. This brings script modules in line with WP_Scripts in which an enqueued script will not print if a dependency is missing. This caused confusion during during beta/RC and led to the creation of #64229 to warn when a script, style, or script module is enqueued with a missing dependency. See that ticket for more details. I had planned for this to be part of 7.0, but given the potential for unexpected breakage, I'll re-milestone for 6.9.1.
I think otherwise that this ticket can be closed.
#7
@
7 months ago
I had the same thing. Previously a script module had "jquery" as dependency and it still enqueued the main file. With 6.9 it skipped enqueing the file. So previously it ignored it, now it drops it. From a "backwards compatiblity" view, a notice and ignoring it would be better then just dropping it completly. Your thoughts?
Ah, I just noticed the "_doing_it_wrong" ticket, so, I support the vision of #64229 :)
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Hi @intdef, welcome to Trac and thanks for the report. Could you provide more information to reproduce this problem, like the code you're using with
wp_enqueue_script_module()and any other environment information - such as active plugins and theme?