[wp-trac] [WordPress Trac] #65165: Script module dependencies may be unavailable on evaluation

WordPress Trac noreply at wordpress.org
Tue May 5 10:03:06 UTC 2026


#65165: Script module dependencies may be unavailable on evaluation
---------------------------+-------------------------
 Reporter:  jonsurrell     |       Owner:  (none)
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  7.0
Component:  Script Loader  |     Version:  trunk
 Severity:  normal         |  Resolution:
 Keywords:                 |     Focuses:  javascript
---------------------------+-------------------------

Comment (by jonsurrell):

 There is a difficult balance we've already observed with script modules
 and blocks where it's important to print the importmap late enough that
 all module dependencies have already been discovered, but early enough
 that it can be used by scripts and modules that require it.

 All major browsers now support multiple import maps with the notable
 exception of Firefox. Firefox 150 (the current version) has added support
 for multiple import maps, but it's behind a configuration flag that
 defaults to disabled.

 Using multiple import maps is ideal, allowing for multiple importmaps to
 be printed as necessary. [https://github.com/guybedford/es-module-shims
 There is a robust polyfill] that was already added ([57492]) and later
 removed ([58952]) due to good browser support for basic importmap
 functionality. It may be worth adding the polyfil for the multiple
 importmap support.

 -----

 Some possible paths forward in no particular order:

 a. Revert [61587] for 7.0, removing the script->module dependency feature
 and the bug.
 b. Add the polyfill and print multiple importmaps as needed.
 c. Always defer scripts that have a dependency on a script module. (This
 seems heavy handed and likely to introduce bugs.)
 d. Document the situation and do nothing. Scripts can depend on modules,
 but authors must understand this limitation and can apply workarounds such
 as deferring their script or waiting for `DOMContentLoaded` before
 attempting to import a module. (This seems undesirable for a number of
 reasons.)

 Options `a` or `b` seem preferable. Removing the feature from 7.0 is safe.
 `b` will require more development late in the 7.0 cycle to address this
 issue.

 I'd welcome other folks ideas and opinions here.

 -----

 [https://github.com/WordPress/ai/pull/482#discussion_r3182513240 This was
 discovered here] with help from @dkotter and @gziolo.

 FYI @westonruter.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/65165#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list