node/doc/api
Joyee Cheung 3e31baeda6
esm: use sync loading/resolving on non-loader-hook thread
ESM resolution and loading is now always synchronous from a
non-loader-hook thread. If no asynchrnous loader hooks are
registered, the resolution/loading is entirely synchronous.
If asynchronous loader hooks are registered, these would be
synchronous on the non-loader-hook thread, and asynchronous
on the loader hook thread.

This avoids several races caused by async/sync loading sharing
the same cache. In particular, asynchronous loader hooks
now works with `require(esm)` - previously it tends to break
due to races.

In addition, when an asynchronous loader hook
returns a promise that never settles, the main thread no longer
silently exits with exit code 13, leaving the code below
any module loading calls silently ignored without being executed.
Instead, it now throws ERR_ASYNC_LOADER_REQUEST_NEVER_SETTLED
which can be caught and handled by the main thread. If the module
request comes from `import()`, the never-settling promise is
now relayed to the result returned by `import()`.

Drive-by: when annotating the error about importing undetectable
named exports from CommonJS, it now no longer reload the source
code of the CommonJS module, and instead reuses format information
cached when the module was loaded for linking.

PR-URL: https://github.com/nodejs/node/pull/60380
Fixes: https://github.com/nodejs/node/issues/59666
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
2025-10-31 20:45:10 +00:00
..
addons.md doc,src,test: replace use of deprecated GetIsolate 2025-10-04 18:48:35 +02:00
assert.md 2025-10-28, Version 25.1.0 (Current) 2025-10-28 20:03:00 +01:00
async_context.md doc: fix typed list formatting 2025-07-15 17:18:42 +00:00
async_hooks.md doc,tools: enforce use of node: prefix 2024-07-21 15:44:27 +00:00
buffer.md doc: fix blob.bytes() heading level 2025-10-16 08:17:53 +00:00
child_process.md doc: fix typo on child_process.md 2025-10-06 09:11:55 +00:00
cli.md doc: correct module loading descriptions 2025-10-31 20:30:23 +00:00
cluster.md doc: fix typed list formatting 2025-07-15 17:18:42 +00:00
console.md 2025-10-08, Version 24.10.0 (Current) 2025-10-08 19:44:10 -03:00
crypto.md doc,crypto: reorder ML-KEM in the asymmetric key types table 2025-10-01 12:25:45 +00:00
debugger.md inspector: introduce the --inspect-wait flag 2024-05-11 18:48:30 +00:00
deprecations.md doc: mention more codemods in deprecations.md 2025-10-27 14:54:31 +01:00
dgram.md 2025-06-09, Version 24.2.0 (Current) 2025-06-09 23:45:29 +02:00
diagnostics_channel.md 2025-09-24, Version 22.20.0 'Jod' (LTS) 2025-09-24 13:04:16 +00:00
dns.md doc: add missing CAA type to dns.resolveAny() & dnsPromises.resolveAny() 2025-10-22 18:43:07 +00:00
documentation.md doc: clarify release candidate stability index 2025-08-02 10:58:21 +00:00
domain.md doc: fix typed list formatting 2025-07-15 17:18:42 +00:00
embedding.md doc: improve c++ embedder API doc 2024-11-01 03:43:53 +00:00
environment_variables.md doc: mark .env files support as stable 2025-10-03 15:43:10 +02:00
errors.md esm: use sync loading/resolving on non-loader-hook thread 2025-10-31 20:45:10 +00:00
esm.md doc: rephrase dynamic import() description 2025-09-12 06:40:24 +00:00
events.md doc: format safely for doc-kit 2025-07-28 20:03:37 +00:00
fs.md 2025-10-15, Version 25.0.0 (Current) 2025-10-15 13:27:47 -03:00
globals.md doc: mention more codemods in deprecations.md 2025-10-27 14:54:31 +01:00
http.md 2025-10-28, Version 25.1.0 (Current) 2025-10-28 20:03:00 +01:00
http2.md 2025-09-24, Version 22.20.0 'Jod' (LTS) 2025-09-24 13:04:16 +00:00
https.md 2025-10-20, Version 22.21.0 'Jod' (LTS) 2025-10-21 01:45:50 +02:00
index.md doc: add new environment variables doc page 2025-07-20 20:53:54 +00:00
inspector.md 2025-08-28, Version 22.19.0 'Jod' (LTS) 2025-08-28 23:08:02 +02:00
intl.md doc: improve documentation about ICU data fallback 2023-09-22 13:24:23 +00:00
module.md doc, module: change async customization hooks to experimental 2025-10-22 14:43:22 +00:00
modules.md doc: format safely for doc-kit 2025-07-28 20:03:37 +00:00
n-api.md node-api: add napi_create_object_with_properties 2025-10-30 14:10:44 +00:00
net.md 2025-08-28, Version 22.19.0 'Jod' (LTS) 2025-08-28 23:08:02 +02:00
os.md doc: fix typed list formatting 2025-07-15 17:18:42 +00:00
packages.md doc: correct module loading descriptions 2025-10-31 20:30:23 +00:00
path.md 2025-09-24, Version 22.20.0 'Jod' (LTS) 2025-09-24 13:04:16 +00:00
perf_hooks.md perf_hooks: move non-standard performance properties to perf_hooks 2025-10-28 00:23:50 +01:00
permissions.md src,permission: add --allow-inspector ability 2025-09-11 20:10:02 +00:00
process.md 2025-10-20, Version 22.21.0 'Jod' (LTS) 2025-10-21 01:45:50 +02:00
punycode.md doc: fix typed list formatting 2025-07-15 17:18:42 +00:00
querystring.md doc: get rid of unnecessary eslint-skip comments 2023-11-22 19:03:33 +00:00
quic.md doc: fix quic session instance typo 2025-08-29 02:24:57 +00:00
readline.md doc: fix typed list formatting 2025-07-15 17:18:42 +00:00
repl.md doc: fix typed list formatting 2025-07-15 17:18:42 +00:00
report.md 2025-01-07, Version 22.13.0 'Jod' (LTS) 2025-01-07 14:36:47 -05:00
single-executable-applications.md 2025-09-24, Version 22.20.0 'Jod' (LTS) 2025-09-24 13:04:16 +00:00
sqlite.md sqlite,doc: fix StatementSync section 2025-10-31 02:46:05 +00:00
stream.md lib: fix isReadable and isWritable return type value 2025-09-07 14:50:36 +00:00
string_decoder.md doc: add esm examples to node:string_decoder 2024-10-26 20:36:25 +00:00
synopsis.md doc: clarify explaination text on how to run the example 2023-10-06 13:37:31 +00:00
test.md 2025-09-24, Version 22.20.0 'Jod' (LTS) 2025-09-24 13:04:16 +00:00
timers.md 2025-06-09, Version 24.2.0 (Current) 2025-06-09 23:45:29 +02:00
tls.md doc: update OpenSSL default security level to 2 2025-09-08 07:57:40 +00:00
tracing.md doc: fix typed list formatting 2025-07-15 17:18:42 +00:00
tty.md doc: fix typed list formatting 2025-07-15 17:18:42 +00:00
typescript.md doc: update decorator documentation to reflect actual policy 2025-10-19 08:34:28 +00:00
url.md doc: mention more codemods in deprecations.md 2025-10-27 14:54:31 +01:00
util.md 2025-10-20, Version 22.21.0 'Jod' (LTS) 2025-10-21 01:45:50 +02:00
v8.md 2025-10-15, Version 25.0.0 (Current) 2025-10-15 13:27:47 -03:00
vm.md 2025-10-20, Version 22.21.0 'Jod' (LTS) 2025-10-21 01:45:50 +02:00
wasi.md doc: fix typed list formatting 2025-07-15 17:18:42 +00:00
webcrypto.md doc,crypto: update subtle.generateKey and subtle.importKey 2025-09-13 08:55:17 +00:00
webstreams.md 2025-09-24, Version 22.20.0 'Jod' (LTS) 2025-09-24 13:04:16 +00:00
worker_threads.md perf_hooks: move non-standard performance properties to perf_hooks 2025-10-28 00:23:50 +01:00
zlib.md doc: add missing Zstd strategy constants 2025-08-19 18:38:44 +00:00