Skip to content

Commit c39b7c2

Browse files
MoLowruyadorno
authored andcommittedSep 12, 2023
esm: add --import flag
PR-URL: #43942 Backport-PR-URL: #49539 Fixes: #40110 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent c224e1b commit c39b7c2

16 files changed

+348
-66
lines changed
 

‎doc/api/cli.md

+22-3
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,8 @@ Only the root context is supported. There is no guarantee that
530530
`globalThis.Array` is indeed the default intrinsic reference. Code may break
531531
under this flag.
532532

533-
To allow polyfills to be added, `--require` runs before freezing intrinsics.
533+
To allow polyfills to be added,
534+
[`--require`][] and [`--import`][] both run before freezing intrinsics.
534535

535536
### `--force-node-api-uncaught-exceptions-policy`
536537

@@ -679,6 +680,18 @@ added: v0.11.15
679680

680681
Specify ICU data load path. (Overrides `NODE_ICU_DATA`.)
681682

683+
### `--import=module`
684+
685+
<!-- YAML
686+
added: REPLACEME
687+
-->
688+
689+
Preload the specified module at startup.
690+
691+
Follows [ECMAScript module][] resolution rules.
692+
Use [`--require`][] to load a [CommonJS module][].
693+
Modules preloaded with `--require` will run before modules preloaded with `--import`.
694+
682695
### `--input-type=type`
683696

684697
<!-- YAML
@@ -1739,8 +1752,9 @@ Preload the specified module at startup.
17391752
Follows `require()`'s module resolution
17401753
rules. `module` may be either a path to a file, or a node module name.
17411754

1742-
Only CommonJS modules are supported. Attempting to preload a
1743-
ES6 Module using `--require` will fail with an error.
1755+
Only CommonJS modules are supported.
1756+
Use [`--import`][] to preload an [ECMAScript module][].
1757+
Modules preloaded with `--require` will run before modules preloaded with `--import`.
17441758

17451759
### `-v`, `--version`
17461760

@@ -1895,6 +1909,7 @@ Node.js options that are allowed are:
18951909
* `--heapsnapshot-signal`
18961910
* `--http-parser`
18971911
* `--icu-data-dir`
1912+
* `--import`
18981913
* `--input-type`
18991914
* `--insecure-http-parser`
19001915
* `--inspect-brk`
@@ -2315,7 +2330,9 @@ done
23152330
[#42511]: https://github.com/nodejs/node/issues/42511
23162331
[Chrome DevTools Protocol]: https://chromedevtools.github.io/devtools-protocol/
23172332
[CommonJS]: modules.md
2333+
[CommonJS module]: modules.md
23182334
[CustomEvent Web API]: https://dom.spec.whatwg.org/#customevent
2335+
[ECMAScript module]: esm.md#modules-ecmascript-modules
23192336
[ECMAScript module loader]: esm.md#loaders
23202337
[Fetch API]: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
23212338
[Modules loaders]: packages.md#modules-loaders
@@ -2333,9 +2350,11 @@ done
23332350
[`--diagnostic-dir`]: #--diagnostic-dirdirectory
23342351
[`--experimental-wasm-modules`]: #--experimental-wasm-modules
23352352
[`--heap-prof-dir`]: #--heap-prof-dir
2353+
[`--import`]: #--importmodule
23362354
[`--openssl-config`]: #--openssl-configfile
23372355
[`--preserve-symlinks`]: #--preserve-symlinks
23382356
[`--redirect-warnings`]: #--redirect-warningsfile
2357+
[`--require`]: #-r---require-module
23392358
[`Atomics.wait()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait
23402359
[`Buffer`]: buffer.md#class-buffer
23412360
[`CRYPTO_secure_malloc_init`]: https://www.openssl.org/docs/man3.0/man3/CRYPTO_secure_malloc_init.html

‎lib/internal/main/check_syntax.js

+21-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// instead of actually running the file.
55

66
const { URL } = require('internal/url');
7+
const { getOptionValue } = require('internal/options');
78
const {
89
prepareMainThreadExecution,
910
markBootstrapComplete,
@@ -38,18 +39,29 @@ if (process.argv[1] && process.argv[1] !== '-') {
3839

3940
markBootstrapComplete();
4041

41-
checkSyntax(source, filename);
42+
loadESMIfNeeded(() => checkSyntax(source, filename));
4243
} else {
4344
markBootstrapComplete();
4445

45-
readStdin((code) => {
46+
loadESMIfNeeded(() => readStdin((code) => {
4647
checkSyntax(code, '[stdin]');
47-
});
48+
}));
4849
}
4950

50-
async function checkSyntax(source, filename) {
51+
function loadESMIfNeeded(cb) {
5152
const { getOptionValue } = require('internal/options');
52-
let isModule = false;
53+
const hasModulePreImport = getOptionValue('--import').length > 0;
54+
55+
if (hasModulePreImport) {
56+
const { loadESM } = require('internal/process/esm_loader');
57+
loadESM(cb);
58+
return;
59+
}
60+
cb();
61+
}
62+
63+
async function checkSyntax(source, filename) {
64+
let isModule = true;
5365
if (filename === '[stdin]' || filename === '[eval]') {
5466
isModule = getOptionValue('--input-type') === 'module';
5567
} else {
@@ -59,11 +71,14 @@ async function checkSyntax(source, filename) {
5971
const format = await defaultGetFormat(new URL(url));
6072
isModule = format === 'module';
6173
}
74+
6275
if (isModule) {
6376
const { ModuleWrap } = internalBinding('module_wrap');
6477
new ModuleWrap(filename, undefined, source, 0, 0);
6578
return;
6679
}
6780

68-
wrapSafe(filename, source);
81+
const { loadESM } = require('internal/process/esm_loader');
82+
const { handleMainPromise } = require('internal/modules/run_main');
83+
handleMainPromise(loadESM((loader) => wrapSafe(filename, source)));
6984
}

‎lib/internal/main/eval_stdin.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ readStdin((code) => {
2424
process._eval = code;
2525

2626
const print = getOptionValue('--print');
27+
const loadESM = getOptionValue('--import').length > 0;
2728
if (getOptionValue('--input-type') === 'module')
2829
evalModule(code, print);
2930
else
3031
evalScript('[stdin]',
3132
code,
3233
getOptionValue('--inspect-brk'),
33-
print);
34+
print,
35+
loadESM);
3436
});

‎lib/internal/main/eval_string.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ markBootstrapComplete();
2222

2323
const source = getOptionValue('--eval');
2424
const print = getOptionValue('--print');
25+
const loadESM = getOptionValue('--import').length > 0;
2526
if (getOptionValue('--input-type') === 'module')
2627
evalModule(source, print);
2728
else
2829
evalScript('[eval]',
2930
source,
3031
getOptionValue('--inspect-brk'),
31-
print);
32+
print,
33+
loadESM);

‎lib/internal/modules/run_main.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ function shouldUseESMLoader(mainPath) {
3333
* (or an empty list when none have been registered).
3434
*/
3535
const userLoaders = getOptionValue('--experimental-loader');
36-
if (userLoaders.length > 0)
36+
/**
37+
* @type {string[]} userImports A list of preloaded modules registered by the user
38+
* (or an empty list when none have been registered).
39+
*/
40+
const userImports = getOptionValue('--import');
41+
if (userLoaders.length > 0 || userImports.length > 0)
3742
return true;
3843
const esModuleSpecifierResolution =
3944
getOptionValue('--experimental-specifier-resolution');

‎lib/internal/process/esm_loader.js

+20-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const {
4+
ArrayIsArray,
45
ObjectCreate,
56
} = primordials;
67

@@ -56,8 +57,23 @@ async function initializeLoader() {
5657

5758
const { getOptionValue } = require('internal/options');
5859
const customLoaders = getOptionValue('--experimental-loader');
60+
const preloadModules = getOptionValue('--import');
61+
const loaders = await loadModulesInIsolation(customLoaders);
5962

60-
if (customLoaders.length === 0) return;
63+
// Hooks must then be added to external/public loader
64+
// (so they're triggered in userland)
65+
esmLoader.addCustomLoaders(loaders);
66+
67+
// Preload after loaders are added so they can be used
68+
if (preloadModules?.length) {
69+
await loadModulesInIsolation(preloadModules, loaders);
70+
}
71+
72+
isESMInitialized = true;
73+
}
74+
75+
function loadModulesInIsolation(specifiers, loaders = []) {
76+
if (!ArrayIsArray(specifiers) || specifiers.length === 0) { return; }
6177

6278
let cwd;
6379
try {
@@ -70,19 +86,14 @@ async function initializeLoader() {
7086
// between internal Node.js and userland. For example, a module with internal
7187
// state (such as a counter) should be independent.
7288
const internalEsmLoader = new ESMLoader();
89+
internalEsmLoader.addCustomLoaders(loaders);
7390

7491
// Importation must be handled by internal loader to avoid poluting userland
75-
const keyedExportsList = await internalEsmLoader.import(
76-
customLoaders,
92+
return internalEsmLoader.import(
93+
specifiers,
7794
pathToFileURL(cwd).href,
7895
ObjectCreate(null),
7996
);
80-
81-
// Hooks must then be added to external/public loader
82-
// (so they're triggered in userland)
83-
await esmLoader.addCustomLoaders(keyedExportsList);
84-
85-
isESMInitialized = true;
8697
}
8798

8899
exports.loadESM = async function loadESM(callback) {

‎lib/internal/process/execution.js

+36-27
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function evalModule(source, print) {
5050
return handleMainPromise(loadESM((loader) => loader.eval(source)));
5151
}
5252

53-
function evalScript(name, body, breakFirstLine, print) {
53+
function evalScript(name, body, breakFirstLine, print, shouldLoadESM = false) {
5454
const CJSModule = require('internal/modules/cjs/loader').Module;
5555
const { kVmBreakFirstLineSymbol } = require('internal/util');
5656
const { pathToFileURL } = require('url');
@@ -62,36 +62,45 @@ function evalScript(name, body, breakFirstLine, print) {
6262
module.filename = path.join(cwd, name);
6363
module.paths = CJSModule._nodeModulePaths(cwd);
6464

65+
const { handleMainPromise } = require('internal/modules/run_main');
6566
const asyncESM = require('internal/process/esm_loader');
6667
const baseUrl = pathToFileURL(module.filename).href;
68+
const { loadESM } = asyncESM;
69+
70+
const runScript = () => {
71+
// Create wrapper for cache entry
72+
const script = `
73+
globalThis.module = module;
74+
globalThis.exports = exports;
75+
globalThis.__dirname = __dirname;
76+
globalThis.require = require;
77+
return (main) => main();
78+
`;
79+
globalThis.__filename = name;
80+
RegExpPrototypeExec(/^/, ''); // Necessary to reset RegExp statics before user code runs.
81+
const result = module._compile(script, `${name}-wrapper`)(() =>
82+
require('vm').runInThisContext(body, {
83+
filename: name,
84+
displayErrors: true,
85+
[kVmBreakFirstLineSymbol]: !!breakFirstLine,
86+
importModuleDynamically(specifier, _, importAssertions) {
87+
const loader = asyncESM.esmLoader;
88+
return loader.import(specifier, baseUrl, importAssertions);
89+
},
90+
}));
91+
if (print) {
92+
const { log } = require('internal/console/global');
93+
log(result);
94+
}
6795

68-
// Create wrapper for cache entry
69-
const script = `
70-
globalThis.module = module;
71-
globalThis.exports = exports;
72-
globalThis.__dirname = __dirname;
73-
globalThis.require = require;
74-
return (main) => main();
75-
`;
76-
globalThis.__filename = name;
77-
RegExpPrototypeExec(/^/, ''); // Necessary to reset RegExp statics before user code runs.
78-
const result = module._compile(script, `${name}-wrapper`)(() =>
79-
require('vm').runInThisContext(body, {
80-
filename: name,
81-
displayErrors: true,
82-
[kVmBreakFirstLineSymbol]: !!breakFirstLine,
83-
importModuleDynamically(specifier, _, importAssertions) {
84-
const loader = asyncESM.esmLoader;
85-
return loader.import(specifier, baseUrl, importAssertions);
86-
},
87-
}));
88-
if (print) {
89-
const { log } = require('internal/console/global');
90-
log(result);
91-
}
96+
if (origModule !== undefined)
97+
globalThis.module = origModule;
98+
};
9299

93-
if (origModule !== undefined)
94-
globalThis.module = origModule;
100+
if (shouldLoadESM) {
101+
return handleMainPromise(loadESM(runScript));
102+
}
103+
return runScript();
95104
}
96105

97106
const exceptionHandlerState = {

‎src/node_options.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -666,10 +666,14 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
666666
AddAlias("-pe", { "--print", "--eval" });
667667
AddAlias("-p", "--print");
668668
AddOption("--require",
669-
"module to preload (option can be repeated)",
670-
&EnvironmentOptions::preload_modules,
669+
"CommonJS module to preload (option can be repeated)",
670+
&EnvironmentOptions::preload_cjs_modules,
671671
kAllowedInEnvvar);
672672
AddAlias("-r", "--require");
673+
AddOption("--import",
674+
"ES module to preload (option can be repeated)",
675+
&EnvironmentOptions::preload_esm_modules,
676+
kAllowedInEnvironment);
673677
AddOption("--interactive",
674678
"always enter the REPL even if stdin does not appear "
675679
"to be a terminal",

‎src/node_options.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ class EnvironmentOptions : public Options {
200200
bool tls_max_v1_3 = false;
201201
std::string tls_keylog;
202202

203-
std::vector<std::string> preload_modules;
203+
std::vector<std::string> preload_cjs_modules;
204+
205+
std::vector<std::string> preload_esm_modules;
204206

205207
std::vector<std::string> user_argv;
206208

+185
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
import { spawnPromisified } from '../common/index.mjs';
2+
import fixtures from '../common/fixtures.js';
3+
import assert from 'node:assert';
4+
import { execPath } from 'node:process';
5+
import { describe, it } from 'node:test';
6+
7+
const cjsEntry = fixtures.path('es-modules', 'cjs-file.cjs');
8+
const cjsImport = fixtures.fileURL('es-modules', 'cjs-file.cjs');
9+
const mjsEntry = fixtures.path('es-modules', 'mjs-file.mjs');
10+
const mjsImport = fixtures.fileURL('es-modules', 'mjs-file.mjs');
11+
12+
13+
describe('import modules using --import', { concurrency: true }, () => {
14+
it('should import when using --eval', async () => {
15+
const { code, signal, stderr, stdout } = await spawnPromisified(
16+
execPath,
17+
[
18+
'--import', mjsImport,
19+
'--eval', 'console.log("log")',
20+
]
21+
);
22+
23+
assert.strictEqual(stderr, '');
24+
assert.match(stdout, /^\.mjs file\r?\nlog\r?\n$/);
25+
assert.strictEqual(code, 0);
26+
assert.strictEqual(signal, null);
27+
});
28+
29+
it('should import when using --eval and --input-type=module', async () => {
30+
const { code, signal, stderr, stdout } = await spawnPromisified(
31+
execPath,
32+
[
33+
'--import', mjsImport,
34+
'--input-type', 'module',
35+
'--eval', 'console.log("log")',
36+
]
37+
);
38+
39+
assert.strictEqual(stderr, '');
40+
assert.match(stdout, /^\.mjs file\r?\nlog\r?\n$/);
41+
assert.strictEqual(code, 0);
42+
assert.strictEqual(signal, null);
43+
});
44+
45+
it('should import when main entrypoint is a cjs file', async () => {
46+
const { code, signal, stderr, stdout } = await spawnPromisified(
47+
execPath,
48+
[
49+
'--import', mjsImport,
50+
cjsEntry,
51+
]
52+
);
53+
54+
assert.strictEqual(stderr, '');
55+
assert.match(stdout, /^\.mjs file\r?\n\.cjs file\r?\n$/);
56+
assert.strictEqual(code, 0);
57+
assert.strictEqual(signal, null);
58+
});
59+
60+
it('should import mjs when entrypoint is a cjs file', async () => {
61+
const { code, signal, stderr, stdout } = await spawnPromisified(
62+
execPath,
63+
[
64+
'--import', mjsImport,
65+
cjsEntry,
66+
]
67+
);
68+
69+
assert.strictEqual(stderr, '');
70+
assert.match(stdout, /^\.mjs file\r?\n\.cjs file\r?\n$/);
71+
assert.strictEqual(code, 0);
72+
assert.strictEqual(signal, null);
73+
});
74+
75+
it('should import cjs when entrypoint is a mjs file', async () => {
76+
const { code, signal, stderr, stdout } = await spawnPromisified(
77+
execPath,
78+
[
79+
'--import', cjsImport,
80+
mjsEntry,
81+
]
82+
);
83+
84+
assert.strictEqual(stderr, '');
85+
assert.match(stdout, /^\.cjs file\r?\n\.mjs file\r?\n$/);
86+
assert.strictEqual(code, 0);
87+
assert.strictEqual(signal, null);
88+
});
89+
90+
it('should import mjs when entrypoint is a cjs file', async () => {
91+
const { code, signal, stderr, stdout } = await spawnPromisified(
92+
execPath,
93+
[
94+
'--import', mjsImport,
95+
cjsEntry,
96+
]
97+
);
98+
99+
assert.strictEqual(stderr, '');
100+
assert.match(stdout, /^\.mjs file\r?\n\.cjs file\r?\n$/);
101+
assert.strictEqual(code, 0);
102+
assert.strictEqual(signal, null);
103+
});
104+
105+
it('should de-duplicate redundant `--import`s', async () => {
106+
const { code, signal, stderr, stdout } = await spawnPromisified(
107+
execPath,
108+
[
109+
'--import', mjsImport,
110+
'--import', mjsImport,
111+
'--import', mjsImport,
112+
cjsEntry,
113+
]
114+
);
115+
116+
assert.strictEqual(stderr, '');
117+
assert.match(stdout, /^\.mjs file\r?\n\.cjs file\r?\n$/);
118+
assert.strictEqual(code, 0);
119+
assert.strictEqual(signal, null);
120+
});
121+
122+
it('should import when running --check', async () => {
123+
const { code, signal, stderr, stdout } = await spawnPromisified(
124+
execPath,
125+
[
126+
'--import', mjsImport,
127+
'--check',
128+
cjsEntry,
129+
]
130+
);
131+
132+
assert.strictEqual(stderr, '');
133+
assert.match(stdout, /^\.mjs file\r?\n$/);
134+
assert.strictEqual(code, 0);
135+
assert.strictEqual(signal, null);
136+
});
137+
138+
it('should import when running --check fails', async () => {
139+
const { code, signal, stderr, stdout } = await spawnPromisified(
140+
execPath,
141+
[
142+
'--import', mjsImport,
143+
'--no-warnings',
144+
'--check',
145+
fixtures.path('es-modules', 'invalid-cjs.js'),
146+
]
147+
);
148+
149+
assert.match(stderr, /SyntaxError: Unexpected token 'export'/);
150+
assert.match(stdout, /^\.mjs file\r?\n$/);
151+
assert.strictEqual(code, 1);
152+
assert.strictEqual(signal, null);
153+
});
154+
155+
it('should import --require before --import', async () => {
156+
const { code, signal, stderr, stdout } = await spawnPromisified(
157+
execPath,
158+
[
159+
'--import', mjsImport,
160+
'--require', cjsEntry,
161+
'--eval', 'console.log("log")',
162+
]
163+
);
164+
165+
assert.strictEqual(stderr, '');
166+
assert.match(stdout, /^\.cjs file\r?\n\.mjs file\r?\nlog\r?\n$/);
167+
assert.strictEqual(code, 0);
168+
assert.strictEqual(signal, null);
169+
});
170+
171+
it('should import a module with top level await', async () => {
172+
const { code, signal, stderr, stdout } = await spawnPromisified(
173+
execPath,
174+
[
175+
'--import', fixtures.fileURL('es-modules', 'esm-top-level-await.mjs'),
176+
fixtures.path('es-modules', 'print-3.mjs'),
177+
]
178+
);
179+
180+
assert.strictEqual(stderr, '');
181+
assert.match(stdout, /^1\r?\n2\r?\n3\r?\n$/);
182+
assert.strictEqual(code, 0);
183+
assert.strictEqual(signal, null);
184+
});
185+
});

‎test/es-module/test-esm-loader-http-imports.mjs

+28-10
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ import http from 'node:http';
55
import path from 'node:path';
66
import { execPath } from 'node:process';
77
import { promisify } from 'node:util';
8-
import { describe, it } from 'node:test';
8+
import { describe, it, after } from 'node:test';
99

1010

1111
const files = {
1212
'main.mjs': 'export * from "./lib.mjs";',
1313
'lib.mjs': 'export { sum } from "./sum.mjs";',
1414
'sum.mjs': 'export function sum(a, b) { return a + b }',
15+
'console.mjs': `
16+
import { sum } from './sum.mjs';
17+
globalThis.sum = sum;
18+
console.log("loaded over http");
19+
`,
1520
};
1621

1722
const requestListener = ({ url }, rsp) => {
@@ -41,13 +46,26 @@ const {
4146
port,
4247
} = server.address();
4348

44-
/**
45-
* ! If more cases are added to this test, they cannot (yet) be concurrent because there is no
46-
* ! `afterAll` teardown in which to close the server.
47-
*/
48-
49-
describe('ESM: http import via loader', { concurrency: false }, () => {
50-
it('should work', async () => {
49+
describe('ESM: http import via loader', { concurrency: true }, () => {
50+
it('should load using --import flag', async () => {
51+
// ! MUST NOT use spawnSync to avoid blocking the event loop
52+
const { code, signal, stderr, stdout } = await spawnPromisified(
53+
execPath,
54+
[
55+
'--no-warnings',
56+
'--loader',
57+
fixtures.fileURL('es-module-loaders', 'http-loader.mjs'),
58+
'--import', `http://${host}:${port}/console.mjs`,
59+
'--eval',
60+
'console.log(sum(1, 2))',
61+
]
62+
);
63+
assert.strictEqual(stderr, '');
64+
assert.match(stdout, /loaded over http\r?\n3/);
65+
assert.strictEqual(code, 0);
66+
assert.strictEqual(signal, null);
67+
});
68+
it('should load using import inside --eval code', async () => {
5169
// ! MUST NOT use spawnSync to avoid blocking the event loop
5270
const { code, signal, stderr, stdout } = await spawnPromisified(
5371
execPath,
@@ -65,7 +83,7 @@ describe('ESM: http import via loader', { concurrency: false }, () => {
6583
assert.strictEqual(stdout, '[Module: null prototype] { sum: [Function: sum] }\n');
6684
assert.strictEqual(code, 0);
6785
assert.strictEqual(signal, null);
68-
69-
server.close(); // ! This MUST come after the final test, but inside the async `it` function
7086
});
87+
88+
after(() => server.close());
7189
});

‎test/fixtures/errors/force_colors.snapshot

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Error: Should include grayed stack trace
88
 at Module._extensions..js (node:internal*modules*cjs*loader:1310:10)
99
 at Module.load (node:internal*modules*cjs*loader:1119:32)
1010
 at Module._load (node:internal*modules*cjs*loader:960:12)
11-
 at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:81:12)
11+
 at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:86:12)
1212
 at node:internal*main*run_main_module:23:47
1313

1414
Node.js *
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { setImmediate } from 'node:timers/promises';
2+
3+
await setImmediate();
4+
console.log(1);
5+
console.log(2);

‎test/fixtures/es-modules/print-3.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log(3);

‎test/message/eval_messages.out

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ SyntaxError: Strict mode code may not include a with statement
88
at Object.runInThisContext (node:vm:*:*)
99
at node:internal/process/execution:*:*
1010
at [eval]-wrapper:*:*
11+
at runScript (node:internal/process/execution:*:*)
1112
at evalScript (node:internal/process/execution:*:*)
1213
at node:internal/main/eval_string:*:*
1314

@@ -24,6 +25,7 @@ Error: hello
2425
at Object.runInThisContext (node:vm:*:*)
2526
at node:internal/process/execution:*:*
2627
at [eval]-wrapper:*:*
28+
at runScript (node:internal/process/execution:*:*)
2729
at evalScript (node:internal/process/execution:*:*)
2830
at node:internal/main/eval_string:*:*
2931

@@ -39,6 +41,7 @@ Error: hello
3941
at Object.runInThisContext (node:vm:*:*)
4042
at node:internal/process/execution:*:*
4143
at [eval]-wrapper:*:*
44+
at runScript (node:internal/process/execution:*:*)
4245
at evalScript (node:internal/process/execution:*:*)
4346
at node:internal/main/eval_string:*:*
4447

@@ -54,6 +57,7 @@ ReferenceError: y is not defined
5457
at Object.runInThisContext (node:vm:*:*)
5558
at node:internal/process/execution:*:*
5659
at [eval]-wrapper:*:*
60+
at runScript (node:internal/process/execution:*:*)
5761
at evalScript (node:internal/process/execution:*:*)
5862
at node:internal/main/eval_string:*:*
5963

‎test/message/stdin_messages.out

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ SyntaxError: Strict mode code may not include a with statement
99
at Object.runInThisContext (node:vm:*)
1010
at node:internal/process/execution:*:*
1111
at [stdin]-wrapper:*:*
12+
at runScript (node:internal/process/execution:*:*)
1213
at evalScript (node:internal/process/execution:*:*)
1314
at node:internal/main/eval_stdin:*:*
1415
at Socket.<anonymous> (node:internal/process/execution:*:*)
1516
at Socket.emit (node:events:*:*)
16-
at endReadableNT (node:internal/streams/readable:*:*)
1717

1818
Node.js *
1919
42
@@ -28,11 +28,11 @@ Error: hello
2828
at Object.runInThisContext (node:vm:*)
2929
at node:internal/process/execution:*:*
3030
at [stdin]-wrapper:*:*
31+
at runScript (node:internal/process/execution:*:*)
3132
at evalScript (node:internal/process/execution:*:*)
3233
at node:internal/main/eval_stdin:*:*
3334
at Socket.<anonymous> (node:internal/process/execution:*:*)
3435
at Socket.emit (node:events:*:*)
35-
at endReadableNT (node:internal/streams/readable:*:*)
3636

3737
Node.js *
3838
[stdin]:1
@@ -45,11 +45,11 @@ Error: hello
4545
at Object.runInThisContext (node:vm:*)
4646
at node:internal/process/execution:*:*
4747
at [stdin]-wrapper:*:*
48+
at runScript (node:internal/process/execution:*:*)
4849
at evalScript (node:internal/process/execution:*:*)
4950
at node:internal/main/eval_stdin:*:*
5051
at Socket.<anonymous> (node:internal/process/execution:*:*)
5152
at Socket.emit (node:events:*:*)
52-
at endReadableNT (node:internal/streams/readable:*:*)
5353

5454
Node.js *
5555
100
@@ -63,11 +63,11 @@ ReferenceError: y is not defined
6363
at Object.runInThisContext (node:vm:*)
6464
at node:internal/process/execution:*:*
6565
at [stdin]-wrapper:*:*
66+
at runScript (node:internal/process/execution:*:*)
6667
at evalScript (node:internal/process/execution:*:*)
6768
at node:internal/main/eval_stdin:*:*
6869
at Socket.<anonymous> (node:internal/process/execution:*:*)
6970
at Socket.emit (node:events:*:*)
70-
at endReadableNT (node:internal/streams/readable:*:*)
7171

7272
Node.js *
7373

0 commit comments

Comments
 (0)
Please sign in to comment.