[wp-trac] [WordPress Trac] #64229: Enqueueing scripts and script modules should warn when dependencies are missing
WordPress Trac
noreply at wordpress.org
Tue Nov 11 04:08:36 UTC 2025
#64229: Enqueueing scripts and script modules should warn when dependencies are
missing
---------------------------+-------------------------
Reporter: westonruter | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 7.0
Component: Script Loader | Version: trunk
Severity: normal | Resolution:
Keywords: needs-patch | Focuses: javascript
---------------------------+-------------------------
Description changed by westonruter:
Old description:
> Given the following plugin code:
>
> {{{#!php
> <?php
> /**
> * Plugin Name: Try in enqueuing classic script and script module with
> missing dependencies
> */
>
> namespace TryEnqueueingScriptsWithMissingDependencies;
>
> add_action(
> 'wp_enqueue_scripts',
> static function () {
> wp_enqueue_script( 'classic-script-with-missing-
> dependency', 'https://example.com/classic-script.js', array( 'classic-
> dependency' ) );
> wp_enqueue_script_module( 'script-module-with-missing-
> dependency', 'https://example.com/script-module.js', array( 'module-
> dependency' ) );
> }
> );
> }}}
>
> In WordPress 6.8, the classic script is ''not'' printed but the script
> module ''is''. However, as of WordPress 6.9, script modules now behave
> the same as classic scripts when they have missing dependencies: the
> script module is not printed. This change was introduced in r60999 to fix
> #63486. See [https://github.com/WordPress/wordpress-
> develop/blob/328ab83beb153ffa6d5378b26bb4ef2ceee49c47/src/wp-includes
> /class-wp-script-modules.php#L724-L727 code in question].
>
> As was extensively
> [https://wordpress.slack.com/archives/C071CRKGKUP/p1762356664084569
> troubleshooted] in the #core-interactivity-api channel in Slack, this
> change in behavior was difficult to debug, and it was difficult to
> identify why a script was not being printed.
>
> Query Monitor actually helpfully warns when attempting to enqueue a
> classic script script that is missing dependencies, but it doesn't
> currently do the same for script modules. This may be due to #60597,
> where `WP_Script_Modules` lacks the necessary accessors.
>
> In any case, WordPress core should itself issue a `_doing_it_wrong()` for
> both classic scripts and script modules whenever there is a missing
> dependency for an enqueued script.
New description:
Given the following plugin code:
{{{#!php
<?php
/**
* Plugin Name: Try in enqueuing classic script and script module with
missing dependencies
*/
namespace TryEnqueueingScriptsWithMissingDependencies;
add_action(
'wp_enqueue_scripts',
static function () {
wp_enqueue_script( 'classic-script-with-missing-
dependency', 'https://example.com/classic-script.js', array( 'classic-
dependency' ) );
wp_enqueue_script_module( 'script-module-with-missing-
dependency', 'https://example.com/script-module.js', array( 'module-
dependency' ) );
}
);
}}}
In WordPress 6.8, the classic script is ''not'' printed but the script
module ''is''. However, as of WordPress 6.9, script modules now behave the
same as classic scripts when they have missing dependencies: the script
module is not printed. This change was introduced in r60999 to fix #63486.
See [https://github.com/WordPress/wordpress-
develop/blob/328ab83beb153ffa6d5378b26bb4ef2ceee49c47/src/wp-includes
/class-wp-script-modules.php#L724-L727 code in question].
As was extensively
[https://wordpress.slack.com/archives/C071CRKGKUP/p1762356664084569
troubleshooted] in the #core-interactivity-api channel in Slack, this
change in behavior was difficult to debug, and it was difficult to
identify why a script was not being printed.
Query Monitor actually helpfully warns when attempting to enqueue a
classic script script that is missing dependencies, but it doesn't
currently do the same for script modules:
[[Image(https://core.trac.wordpress.org/raw-attachment/ticket/64229/query-
monitor.png)]]
This may be due to #60597, where `WP_Script_Modules` lacks the necessary
accessors.
In any case, WordPress core should itself issue a `_doing_it_wrong()` for
both classic scripts and script modules whenever there is a missing
dependency for an enqueued script.
--
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64229#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list