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

Blog: add more information about require(esm) in v23 #7126

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/site/pages/en/blog/release/v23.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ We’re excited to announce the release of Node.js 23! Key highlights include:
Node.js 23 will replace Node.js 22 as the ‘Current’ release line when Node.js 22 enters long-term support (LTS) later this month.
According to the release schedule, Node.js 23 will remain the ‘Current’ release for the next six months, until April 2025.

### `require(esm)` is now enabled by default

Support for loading native ES modules using `require()` had been available on v20 and v22 under the command line flag `--experimental-require-module`. In v23, this feature is now enabled by default. This feature is still experimental, and we are looking for user feedback to make more final tweaks before fully stabilizing it. For this reason, on v23, when the Node.js instance encounters a native ES module in `require()` for the first time, it will emit an experimental warning.

If there happens to be any regressions caused by this feature, users can report it to the Node.js issue tracker. Meanwhile this feature can also be disabled using `--no-experimental-require-module` as a workaround. We expect to test this feature using v23, find out any potential regressions and make adjustments accordingly, before backporting the unflagging to v22. This will likely happen in a later semver-minor release after the the LTS promotion at the end of October.
RafaelGSS marked this conversation as resolved.
Show resolved Hide resolved

With this feature enabled, Node.js will no longer throw `ERR_REQUIRE_ESM` if `require()` is used to load a ES module. It can, however, throw `ERR_REQUIRE_ASYNC_MODULE` if the ES module being loaded or its dependencies contain top-level `await`. When the ES module is loaded successfully by `require()`, the returned object will be a ES module namespace object similar to what's returned by `import()`, and can be checked using `util.isModuleNamespaceObject()`.

Users can check `process.features.require_module` to see whether `require(esm)` is enabled in the current Node.js instance. For packages, the `"module-sync"` exports condition can be used as a way to detect `require(esm)` support in the current Node.js instance and allow both `require()` and `import` to load the same native ES module. See [the documentation](https://nodejs.org/docs/latest/api/modules.html#loading-ecmascript-modules-using-require) for more details about this feature.

### Other Notable Changes

- \[[`7ad0cc3e57`](https://github.com/nodejs/node/commit/7ad0cc3e57)] - **(SEMVER-MAJOR)** **build**: remove support for 32-bit Windows (Michaël Zasso) [#53184](https://github.com/nodejs/node/pull/53184)
Expand Down
Loading