From 0521928ad341dfb6f5dedda0ae65a3ca292405e7 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 16 Oct 2024 17:08:42 +0200 Subject: [PATCH 1/2] Blog: add more information about require(esm) in v23 --- apps/site/pages/en/blog/release/v23.0.0.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/site/pages/en/blog/release/v23.0.0.md b/apps/site/pages/en/blog/release/v23.0.0.md index a420f351c4870..97d7eafc8d7c4 100644 --- a/apps/site/pages/en/blog/release/v23.0.0.md +++ b/apps/site/pages/en/blog/release/v23.0.0.md @@ -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. + +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) From 77bfebdc589e751a9e4646346452051b0c961c5b Mon Sep 17 00:00:00 2001 From: Rafael Gonzaga Date: Wed, 16 Oct 2024 12:25:10 -0300 Subject: [PATCH 2/2] Update apps/site/pages/en/blog/release/v23.0.0.md Co-authored-by: Antoine du Hamel Signed-off-by: Rafael Gonzaga --- apps/site/pages/en/blog/release/v23.0.0.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/site/pages/en/blog/release/v23.0.0.md b/apps/site/pages/en/blog/release/v23.0.0.md index 97d7eafc8d7c4..e17c87c636ae1 100644 --- a/apps/site/pages/en/blog/release/v23.0.0.md +++ b/apps/site/pages/en/blog/release/v23.0.0.md @@ -20,9 +20,9 @@ According to the release schedule, Node.js 23 will remain the ‘Current’ rele ### `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. +Support for loading native ES modules using `require()` had been available on v20.x and v22.x under the command line flag `--experimental-require-module`. In v23.x, 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.x, 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. +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.x, find out any potential regressions and make adjustments accordingly, before backporting the unflagging to v22.x. This will likely happen in a later semver-minor release after the the LTS promotion at the end of October. 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()`.