Skip to content

[RFC] Migrate webpack-encore to ESM #1312

Open
@stof

Description

@stof

More and more npm packages are shipping as ESM. In node, the compatibility between ESM and CommonJS has some limitation:

  • an ES module can import a CommonJS module
  • an ES module can dynamically import a CommonJS module
  • a CommonJS module cannot import an ES module (Node 22 has an experimental feature allowing it for synchronous object graphs, i.e. ES modules that don't use top-level await)
  • a CommonJS module can dynamically import an ES module through await import(...) (but this can only be used in an async context)

Shipping Encore as a CommonJS module means that we cannot upgrade our dependencies to versions that have migrated to ESM (as Encore.getConfig() is a synchronous API, any solution requiring an async context is a no-go).

Migrating to ESM needs to be done in a new major version as it is a BC break for downstream projects. This will require writing the webpack.config.js file in ESM, either by using type=module in the package.json or by using webpack.config.mjs instead (which is supported by webpack)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions