mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
esm: fix loading of CJS modules from ESM
PR-URL: https://github.com/nodejs/node/pull/49500 Fixes: https://github.com/nodejs/node/issues/49497 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me>
This commit is contained in:
parent
cfe4166f0f
commit
fdc65d9769
@ -279,7 +279,8 @@ translators.set('commonjs', async function commonjsStrategy(url, source,
|
|||||||
// obtained by calling the monkey-patchable CJS loader.
|
// obtained by calling the monkey-patchable CJS loader.
|
||||||
const cjsLoader = source == null ? (module, source, url, filename) => {
|
const cjsLoader = source == null ? (module, source, url, filename) => {
|
||||||
try {
|
try {
|
||||||
module.load(filename);
|
assert(module === CJSModule._cache[filename]);
|
||||||
|
CJSModule._load(filename);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
enrichCJSError(err, source, url);
|
enrichCJSError(err, source, url);
|
||||||
throw err;
|
throw err;
|
||||||
|
7
test/es-module/test-esm-recursive-cjs-dependencies.mjs
Normal file
7
test/es-module/test-esm-recursive-cjs-dependencies.mjs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import '../common/index.mjs';
|
||||||
|
import { strictEqual } from 'node:assert';
|
||||||
|
|
||||||
|
import '../fixtures/recursive-a.cjs';
|
||||||
|
|
||||||
|
strictEqual(global.counter, 1);
|
||||||
|
delete global.counter;
|
6
test/fixtures/recursive-a.cjs
vendored
Normal file
6
test/fixtures/recursive-a.cjs
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
global.counter ??= 0;
|
||||||
|
global.counter++;
|
||||||
|
|
||||||
|
require('./recursive-b.cjs');
|
3
test/fixtures/recursive-b.cjs
vendored
Normal file
3
test/fixtures/recursive-b.cjs
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
require('./recursive-a.cjs');
|
Loading…
Reference in New Issue
Block a user