Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Migrate webpack-encore to ESM #1312

Open
stof opened this issue Aug 30, 2024 · 1 comment
Open

[RFC] Migrate webpack-encore to ESM #1312

stof opened this issue Aug 30, 2024 · 1 comment

Comments

@stof
Copy link
Member

stof commented Aug 30, 2024

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)

@Kocal
Copy link
Member

Kocal commented Aug 30, 2024

I'm 100% of favor of migrating Encore to ESM, it's something I've also thought recently.

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).

Yeah, especially with #985 which forced us to introduce rpc-sync dependency to make ESLint API sync, and here in #1303 where I couldn't upgrade to an ESM version (and #1313 aswell).

Also, do we want to write JavaScript ESM compatible code, or do we want to add an additional build step like... TypeScript?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants