Skip to content

JS Module Scripts in more contexts #869

Closed

Description

@PolariTOON

Description

ESM has been available in all major browsers through HTML's <script type="module"> for years now and more recently in Workers and Worklets, however JS execution in browsers is not limited to these contexts.

This issue is about improving interoperability for ESM in contexts where browser support is partial, that is to say, other types of documents (XHTML, SVG) and specialized types of worker (Service Workers).

Contexts without any known integration effort for ESM, such as content scripts, would not be included in this proposal.

Specification

See https://tc39.es/ecma262/#sec-modules for the main spec defining modules though this issue is more about their integration in multiple other consuming specs (see links below)

Additional Signals

Site Breakage and Workaround

Classic JS scripts and JS module scripts (or ESM for short) are two types of scripts with incompatible grammars and different sets of features. While support for some new features (static imports, top-level await...) is restricted to ESM, ESM is not yet available everywhere in browsers, making writing or consuming isomorphic code difficult. For example, one cannot write a module that works in all browsers both in a HTML document, a XHTML document, a SVG document and a Service Worker. Without transpilation, the workaround is often using classic scripts and not benefiting from these newer syntax-enabled features, as they are not really polyfillable and detecting support for them is not straightforward. Of course the other way is not targeting some browsers at all 😢

Integration specs, existing tests, documentation and browser bugs

This issue is about improving interoperability for ESM in contexts where browser support is already partial, such as:

Out of scope features

Contexts without enough signal from browsers to integrate ESM in them would not be included in this effort, such as:

  • scripts executed via WorkerGlobalScope.importScripts(...) in Workers
  • content scripts executed via {browser,chrome}.{scripting,tabs}.executeScript(...) in Web Extensions
  • content scripts defined via the "content_scripts" key in Web Extension Manifests
  • API scripts defined via the "user_scripts.api_script" key in Web Extension Manifests
  • background scripts defined via the "background.scripts" key in Web Extension Manifests
  • dynamic import(...) in Service Workers ( see How should import() work in service workers? w3c/ServiceWorker#1585 )

Activity

  1. rektide commented on Nov 26, 2024

    @rektide

    Please! 10th anniversary of modules, and how partial the web is at allowing modules to be used is a bad look.

    Also related is #715 , on import-maps not being usable in workers. Without import-maps, the usability of modules is very low, requiring modules to be rewritten/mangled from their authored form. Import-maps are what make modules modular and feel critical to the equation of modules being viable & successful.

  2. wpt-interop commented on Feb 13, 2025

    @wpt-interop
    Collaborator

    Thank you for proposing JS Module Scripts in more contexts for inclusion in Interop 2025.

    We wanted to let you know that this proposal was not selected to be part of Interop this year.

    On behalf of the entire Interop team, thank you for submitting this proposal for consideration. We got many more proposals than we could include in this year's project, necessitating some difficult choices. Please note this should not be taken as a comment on the technology as a whole, or our willingness to consider it for Interop in the future. We appreciate the work you put into your proposal, and would welcome your participation in future rounds of Interop.

    For an overview of our process, see proposal selection. Thank you again for contributing to Interop 2025.

    Posted on behalf of the Interop team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    focus-area-proposal

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions