node/test/fixtures/es-modules
Joyee Cheung d7fdbb994c
module: mark evaluation rejection in require(esm) as handled
Previously the implemention of require(esm) only converted the
rejected promise from module evaluation into an error, but the
rejected promise was still treated as a pending unhandled
rejection by the promise rejection callback, because the promise
is created by V8 internals and we don't get a chance to mark
it as handled, so the rejection incorrectly marked as unhandled
would still go through unhandled rejection handling (if no
global listener is set, the default handling would print a warning
and make the Node.js instance exit with 1).

This patch fixes it by calling into the JS promise rejection
callback to mark the evalaution rejection handled so that
it doesn't go through unhandled rejection handling.

PR-URL: https://github.com/nodejs/node/pull/56122
Fixes: https://github.com/nodejs/node/issues/56115
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2024-12-05 16:12:50 +00:00
..
cjs-esm-esm-cycle module: cache synchronous module jobs before linking 2024-05-09 00:25:14 +00:00
deprecated-folders-ignore module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
dynamic-import module: implement NODE_COMPILE_CACHE for automatic on-disk code caching 2024-04-17 23:39:45 +02:00
esm-cjs-esm-cycle module: disallow CJS <-> ESM edges in a cycle from require(esm) 2024-04-08 14:45:55 +00:00
esm-cjs-esm-esm-cycle module: disallow CJS <-> ESM edges in a cycle from require(esm) 2024-04-08 14:45:55 +00:00
esm-esm-cjs-esm-cycle module: disallow CJS <-> ESM edges in a cycle from require(esm) 2024-04-08 14:45:55 +00:00
esm-esm-cjs-esm-esm-cycle module: disallow CJS <-> ESM edges in a cycle from require(esm) 2024-04-08 14:45:55 +00:00
exports-both module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
exports-import-default module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
exports-import-only module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
exports-require-only module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
folder%25with percentage# esm: fix hint on invalid module specifier 2023-12-23 20:38:08 +00:00
json-cache
legacy-main-resolver src,lib: reducing C++ calls of esm legacy main resolve 2023-07-03 18:42:47 +00:00
module-condition module: implement the "module-sync" exports condition 2024-09-25 06:35:26 +00:00
module-counter-by-type loader: return package format from defaultResolve if known 2021-12-13 20:44:00 +00:00
package-cjs-named-error module: fix crash on multiline named cjs imports 2020-09-22 12:49:40 -04:00
package-default-extension module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
package-ends-node_modules src: do not treat all paths ending with node_modules as such 2023-12-25 11:44:26 +00:00
package-type-commonjs esm: bypass CJS loader in default load under `--default-type=module` 2023-11-10 09:20:46 +01:00
package-type-module esm: detect ESM syntax in ambiguous JavaScript 2023-10-20 15:44:56 +00:00
package-without-pjson loader: return package format from defaultResolve if known 2021-12-13 20:44:00 +00:00
package-without-type module: remove --experimental-default-type 2024-12-02 22:43:55 +00:00
pjson-invalid esm: better package.json parser errors 2020-09-11 05:09:44 -07:00
pjson-main
pkgimports module: fix segment deprecation for imports field 2022-10-13 07:31:31 -07:00
require-and-import module: fix submodules loaded by require() and import() 2024-04-16 14:07:44 +00:00
self-deprecated-folders module: runtime deprecate subpath folder mappings 2020-10-30 12:12:56 -04:00
test_node_modules module: do not warn when require(esm) comes from node_modules 2024-11-23 11:28:47 +00:00
tla module: allow ESM that failed to be required to be re-imported 2024-10-28 12:21:22 +00:00
transpiled-cjs-require-module module: add __esModule to require()'d ESM 2024-07-11 18:59:31 +00:00
builtin-imports-case.mjs module: fix builtin reexport tracing 2020-10-04 10:30:13 -07:00
cjs-esm-esm.js esm: refine ERR_REQUIRE_ESM errors 2021-07-15 08:52:37 -07:00
cjs-esm.js module: fix ERR_REQUIRE_ESM error for null frames 2021-07-31 02:32:19 +00:00
cjs-exports-invalid.mjs module: refine module type mismatch error cases 2020-09-30 20:46:01 -07:00
cjs-exports.mjs esm: export 'module.exports' on ESM CJS wrapper 2024-10-02 12:30:23 -07:00
cjs-file.cjs
cjs.js
conditional-exports.js module: add warnings for experimental flags 2019-12-04 22:36:37 -05:00
conditional-exports.mjs module: expose exports conditions to loaders 2020-04-03 01:29:39 +02:00
data-import.mjs module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
dep1.js module: fix builtin reexport tracing 2020-10-04 10:30:13 -07:00
dep2.js module: fix builtin reexport tracing 2020-10-04 10:30:13 -07:00
es-note-error-1.cjs module: only try to enrich CJS syntax errors 2020-10-19 18:41:10 +00:00
es-note-error-1.mjs module: only try to enrich CJS syntax errors 2020-10-19 18:41:10 +00:00
es-note-error-2.cjs module: only try to enrich CJS syntax errors 2020-10-19 18:41:10 +00:00
es-note-error-2.mjs module: only try to enrich CJS syntax errors 2020-10-19 18:41:10 +00:00
es-note-error-3.cjs module: only try to enrich CJS syntax errors 2020-10-19 18:41:10 +00:00
es-note-error-3.mjs module: only try to enrich CJS syntax errors 2020-10-19 18:41:10 +00:00
es-note-error-4.cjs module: only try to enrich CJS syntax errors 2020-10-19 18:41:10 +00:00
es-note-error-4.mjs module: only try to enrich CJS syntax errors 2020-10-19 18:41:10 +00:00
es-note-promiserej-import-2.cjs module: add warning when import,export is detected in CJS context 2019-08-13 11:19:48 -07:00
es-note-unexpected-export-1.cjs module: add warning when import,export is detected in CJS context 2019-08-13 11:19:48 -07:00
es-note-unexpected-export-2.cjs module: add warning when import,export is detected in CJS context 2019-08-13 11:19:48 -07:00
es-note-unexpected-import-1.cjs module: add warning when import,export is detected in CJS context 2019-08-13 11:19:48 -07:00
es-note-unexpected-import-3.cjs module: add warning when import,export is detected in CJS context 2019-08-13 11:19:48 -07:00
es-note-unexpected-import-4.cjs module: add warning when import,export is detected in CJS context 2019-08-13 11:19:48 -07:00
es-note-unexpected-import-5.cjs module: add warning when import,export is detected in CJS context 2019-08-13 11:19:48 -07:00
esm-snapshot-mutator.js
esm-snapshot.js
esm-top-level-await.mjs module: execute `--import` sequentially 2023-11-01 12:38:01 +00:00
export-es-module-2.mjs module: add __esModule to require()'d ESM 2024-07-11 18:59:31 +00:00
export-es-module.mjs module: add __esModule to require()'d ESM 2024-07-11 18:59:31 +00:00
export-name-code-injection.wasm module: fix code injection through export names 2023-10-13 18:03:52 -03:00
export-name-code-injection.wat module: fix code injection through export names 2023-10-13 18:03:52 -03:00
export-name-syntax-error.wasm module: fix code injection through export names 2023-10-13 18:03:52 -03:00
export-name-syntax-error.wat module: fix code injection through export names 2023-10-13 18:03:52 -03:00
exports-cases.js deps: update to cjs-module-lexer@1.2.1 2021-04-30 14:43:48 +02:00
exports-cases2.js module: named exports for CJS via static analysis 2020-09-28 18:27:25 -07:00
exports-cases3.js module: named exports for CJS via static analysis 2020-09-28 18:27:25 -07:00
file.ext esm: consolidate ESM loader hooks 2021-09-11 18:08:35 -07:00
file.unknown esm: consolidate ESM loader hooks 2021-09-11 18:08:35 -07:00
import-data-url.mjs lib,esm: handle bypass network-import via data: 2024-07-12 12:48:54 +00:00
import-esm.mjs module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
import-invalid-ext.mjs esm: use correct error arguments 2019-05-20 10:26:23 -04:00
import-invalid-pjson.mjs esm: share package.json cache between ESM and CJS loaders 2020-05-24 16:22:31 -07:00
import-json-named-export.mjs esm: use import attributes instead of import assertions 2023-10-14 03:52:38 +00:00
import-name.wasm module: fix code injection through export names 2023-10-13 18:03:52 -03:00
import-name.wat module: fix code injection through export names 2023-10-13 18:03:52 -03:00
import-process-exit.mjs
import-resolve-exports.mjs esm: move hook execution to separate thread 2023-04-13 09:35:17 +02:00
imported-esm.mjs module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
imports-loose.mjs esm: --experimental-default-type flag to flip module defaults 2023-09-29 06:18:44 +00:00
imports-noext.mjs esm: --experimental-default-type flag to flip module defaults 2023-09-29 06:18:44 +00:00
invalid-cjs.js module: refine module type mismatch error cases 2020-09-30 20:46:01 -07:00
invalid-posix-host.mjs esm: identify parent importing a url with invalid host 2023-09-23 05:41:26 +00:00
json-modules.mjs esm: use import attributes instead of import assertions 2023-10-14 03:52:38 +00:00
loop.mjs doc, lib, src, test, tools: fix assorted typos 2019-08-12 16:00:22 -07:00
loose.js module: remove --experimental-default-type 2024-12-02 22:43:55 +00:00
message.mjs
mjs-file.mjs
noext
noext-esm esm: --experimental-default-type flag to flip module defaults 2023-09-29 06:18:44 +00:00
noext-wasm esm: --experimental-default-type flag to flip module defaults 2023-09-29 06:18:44 +00:00
pattern-trailing-slash.mjs module: deprecate trailing slash pattern mappings 2021-09-14 23:58:56 -07:00
print-3.mjs esm: add `--import` flag 2022-07-31 04:08:02 +01:00
print-entrypoint.mjs module: support loading entrypoint as url 2024-09-27 15:26:48 +08:00
process-exit.mjs
reference-error-esm.js module: mark evaluation rejection in require(esm) as handled 2024-12-05 16:12:50 +00:00
reference-error.mjs module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
require-cjs.mjs module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
require-esm-throws-with-loaders.js esm: move hooks test with others 2024-06-25 10:08:44 +00:00
require-module.js module: trim off internal stack frames for require(esm) warnings 2024-10-29 18:29:27 +01:00
require-reference-error.cjs module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
require-syntax-error.cjs module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
require-throw-error.cjs module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
required-cjs.js module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
runmain.mjs esm: move hook execution to separate thread 2023-04-13 09:35:17 +02:00
runtime-error-esm.js module: mark evaluation rejection in require(esm) as handled 2024-12-05 16:12:50 +00:00
should-not-be-resolved.mjs module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
simple.wasm esm: --experimental-wasm-modules integration support 2019-05-17 02:25:20 +02:00
simple.wat esm: --experimental-wasm-modules integration support 2019-05-17 02:25:20 +02:00
stateful.mjs esm: consolidate ESM loader hooks 2021-09-11 18:08:35 -07:00
symlink.mjs
synchronous-rejection-esm.js module: mark evaluation rejection in require(esm) as handled 2024-12-05 16:12:50 +00:00
syntax-error.mjs module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
test-esm-comma,.mjs lib: fix regular expression to detect `/` and `\` 2021-10-21 14:55:00 +00:00
test-esm-double-encoding-native%20.mjs
test-esm-ok.mjs
throw-error.mjs module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
wasm-dep.mjs esm: --experimental-wasm-modules integration support 2019-05-17 02:25:20 +02:00
wasm-modules.mjs module: add warnings for experimental flags 2019-12-04 22:36:37 -05:00