Skip to content

Commit 8c00119

Browse files
fixup! module: unflag --experimental-require-module
Co-authored-by: Aviv Keller <[email protected]>
1 parent 4d70568 commit 8c00119

File tree

5 files changed

+14
-19
lines changed

5 files changed

+14
-19
lines changed

lib/internal/modules/esm/loader.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,8 @@ class ModuleLoader {
373373
defaultLoadSync ??= require('internal/modules/esm/load').defaultLoadSync;
374374
const loadResult = defaultLoadSync(url, { format, importAttributes });
375375

376-
let finalFormat = loadResult.format;
377376
// Use the synchronous commonjs translator which can deal with cycles.
378-
if (finalFormat === 'commonjs') {
379-
finalFormat = 'commonjs-sync';
380-
}
377+
let finalFormat = loadResult.format === 'commonjs' ? 'commonjs-sync' : loadResult.format;
381378

382379
if (finalFormat === 'wasm') {
383380
assert.fail('WASM is currently unsupported by require(esm)');

test/es-module/test-cjs-esm-warn.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// This used to test require(esm) throws ERR_REQUIRE_ESM, which is no longer the case
2-
// since require(esm) has been implemented. It's now repurposed to test that the
3-
// previous behavior can be kept when --no-experimental-require-module is passed.
1+
// Previously, this tested that require(esm) throws ERR_REQUIRE_ESM, which is no longer applicable
2+
// since require(esm) is now supported. The test has been repurposed to ensure that the old behavior
3+
// is preserved when the --no-experimental-require-module flag is used.
44
'use strict';
55

66
const { spawnPromisified } = require('../common');

test/es-module/test-esm-type-field-errors-2.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// Flags: --no-experimental-require-module
2-
// This used to test require(esm) throws ERR_REQUIRE_ESM, which is no longer the case
3-
// since require(esm) has been implemented. It's now repurposed to test that the
4-
// previous behavior can be kept when --no-experimental-require-module is passed.
2+
// Previously, this tested that require(esm) throws ERR_REQUIRE_ESM, which is no longer applicable
3+
// since require(esm) is now supported. The test has been repurposed to ensure that the old behavior
4+
// is preserved when the --no-experimental-require-module flag is used.
55

66
'use strict';
77
require('../common');
88
const assert = require('assert');
99
const { describe, it } = require('node:test');
1010

11-
describe('ESM type field errors', () => {
12-
it('Expect CJS to fail loading from type: module package.', () => {
11+
describe('Errors related to ESM type field', () => {
12+
it('Should throw an error when loading CJS from a `type: "module"` package.', () => {
1313
assert.throws(() => require('../fixtures/es-modules/package-type-module/index.js'), {
1414
code: 'ERR_REQUIRE_ESM'
1515
});

test/es-module/test-require-module-preload.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ const { fixturesDir } = require('../common/fixtures');
66

77
const warningRE = /ExperimentalWarning: Support for loading ES Module in require/;
88
function testPreload(preloadFlag) {
9-
let stderr = warningRE;
10-
if (preloadFlag == '--import') {
11-
stderr = undefined; // The warning is only emitted when ESM is loaded by --require.
12-
}
9+
// The warning is only emitted when ESM is loaded by --require.
10+
const stderr = preloadFlag !== '--import' ? warningRE : undefined;
1311

1412
// Test named exports.
1513
{

test/parallel/test-require-mjs.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Flags: --no-experimental-require-module
2-
// This used to test require(esm) throws ERR_REQUIRE_ESM, which is no longer the case
3-
// since require(esm) has been implemented. It's now repurposed to test that the
4-
// previous behavior can be kept when --no-experimental-require-module is passed.
2+
// Previously, this tested that require(esm) throws ERR_REQUIRE_ESM, which is no longer applicable
3+
// since require(esm) is now supported. The test has been repurposed to ensure that the old behavior
4+
// is preserved when the --no-experimental-require-module flag is used.
55

66
'use strict';
77
require('../common');

0 commit comments

Comments
 (0)