node/test/es-module/test-import-preload-require-cycle.js
Joyee Cheung 8c17ceb38f
module: allow cycles in require() in the CJS handling in ESM loader
When --import is used, the ESM loader is used to handle even pure
CJS entry points, and it can run into CJS module facades in the
evaluating state when the parent CJS module is being evaluated.
In this case it should be allowed, since the ESM <-> CJS cycles
that are meant to be disallowed (for the time being) should
already be detected before evaluation and wouldn't get here,
and CJS <-> CJS cycles are fine.

PR-URL: https://github.com/nodejs/node/pull/58598
Fixes: https://github.com/nodejs/node/issues/58515
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
2025-06-11 09:33:16 +00:00

20 lines
472 B
JavaScript

'use strict';
// This tests that --import preload does not break CJS entry points that contains
// require cycles.
require('../common');
const fixtures = require('../common/fixtures');
const { spawnSyncAndAssert } = require('../common/child_process');
spawnSyncAndAssert(
process.execPath,
[
'--import',
fixtures.fileURL('import-require-cycle/preload.mjs'),
fixtures.path('import-require-cycle/c.js'),
],
{
stdout: /cycle equality true/,
}
);