node/lib/internal
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
..
assert assert: allow printf-style messages as assertion error 2025-10-17 20:15:17 +00:00
async_local_storage async_hooks: ensure AsyncLocalStore instances work isolated 2025-05-06 18:00:56 +00:00
bootstrap lib,src: cache ModuleWrap.hasAsyncGraph 2025-09-11 12:54:24 +00:00
child_process child_process: fix parsing messages with splitted length field 2025-01-18 19:39:56 +00:00
cluster lib: add flag to drop connection when running in cluster mode 2024-10-17 15:11:41 +00:00
console console: allow per-stream inspectOptions option 2025-10-03 16:11:08 +02:00
crypto src: update crypto.getCipherInfo() to use DictionaryTemplate 2025-10-05 14:05:35 +00:00
debugger debugger: fix behavior of plain object exec in debugger repl 2025-03-18 19:30:31 +00:00
dns meta: enable jsdoc/check-tag-names rule 2025-07-18 09:28:21 +00:00
errors lib: add source map support for assert messages 2025-09-11 10:37:46 +00:00
events lib: remove Symbol[Async]Dispose polyfills 2024-10-07 09:47:44 +00:00
fs lib: revert to using default derived class constructors 2025-08-30 14:28:10 +00:00
http2 http2: rename variable to additionalPseudoHeaders 2025-10-13 08:31:02 +00:00
inspector inspector: support handshake response for websocket inspection 2025-10-14 07:06:15 +00:00
legacy tools: add lint rule to keep primordials in ASCII order 2024-04-21 16:53:08 +00:00
main src: fix timing of snapshot serialize callback 2025-10-28 00:15:55 +00:00
modules esm: use sync loading/resolving on non-loader-hook thread 2025-10-31 20:45:10 +00:00
per_context perf_hooks: fix stack overflow error 2025-10-13 10:05:45 +02:00
perf perf_hooks: fix stack overflow error 2025-10-13 10:05:45 +02:00
process module: refactor and clarify async loader hook customizations 2025-10-23 13:42:23 +00:00
quic lib: fix typo in QuicSessionStats 2025-10-10 04:16:56 +00:00
readline repl: fix cpu overhead pasting big strings to the REPL 2025-09-14 00:06:47 +00:00
repl repl: move completion logic to internal module 2025-10-08 07:37:22 +00:00
source_map lib: add source map support for assert messages 2025-09-11 10:37:46 +00:00
streams stream: don't try to read more if reading 2025-10-30 08:55:51 +00:00
test v8: implement v8.queryObjects() for memory leak regression testing 2024-03-02 22:11:30 +00:00
test_runner esm: use sync loading/resolving on non-loader-hook thread 2025-10-31 20:45:10 +00:00
tls tls: avoid external memory leak on invalid protocol versions 2025-10-26 16:29:49 +00:00
util util: fix stylize of special properties in inspect 2025-10-31 08:33:38 +00:00
v8 src: fix timing of snapshot serialize callback 2025-10-28 00:15:55 +00:00
vm vm: make vm.Module.evaluate() conditionally synchronous 2025-10-18 08:20:47 +00:00
watch_mode watch: check parent and child path properly 2025-04-06 09:48:53 +02:00
webstreams stream: add brotli support to CompressionStream and DecompressionStream 2025-08-21 02:22:19 +00:00
worker meta: enable jsdoc/check-tag-names rule 2025-07-18 09:28:21 +00:00
abort_controller.js meta: enable jsdoc/check-tag-names rule 2025-07-18 09:28:21 +00:00
assert.js lib: prefer logical assignment 2024-10-09 06:42:16 +00:00
async_context_frame.js lib: use Map primordial for ActiveAsyncContextFrame 2025-04-08 17:51:08 +00:00
async_hooks.js lib: remove redundant destroyHook checks 2025-10-08 12:11:43 +00:00
blob.js lib: fix typo in createBlobReaderStream 2025-10-27 14:14:15 +00:00
blocklist.js net: update net.blocklist to allow file save and file management 2025-07-08 20:37:51 +00:00
buffer.js lib: revert to using default derived class constructors 2025-08-30 14:28:10 +00:00
child_process.js child_process: move _channel to end-of-life 2025-06-02 16:25:50 +00:00
cli_table.js lib: align console.table row to the left 2023-10-28 01:14:22 +00:00
constants.js lib: add trailing commas to more internal files 2023-02-26 11:34:02 +01:00
data_url.js meta: enable jsdoc/check-tag-names rule 2025-07-18 09:28:21 +00:00
dgram.js lib: enforce ASCII order in error code imports 2024-04-23 17:05:38 +00:00
encoding.js util: reduce TextEncoder.encodeInto function size 2025-10-23 14:38:22 +00:00
error_serdes.js lib: avoid StackOverflow on serializeError 2025-04-29 21:12:29 +00:00
errors.js esm: use sync loading/resolving on non-loader-hook thread 2025-10-31 20:45:10 +00:00
event_target.js lib: implement passive listener behavior per spec 2025-10-04 03:17:35 +00:00
file.js buffer: correctly apply prototype to cloned File / Blob 2024-09-28 22:05:58 +00:00
fixed_queue.js lib: ensure no holey array in fixed_queue 2024-09-02 01:42:44 +00:00
freelist.js http: remove unused hasItems() from freelist 2019-12-03 15:00:45 -08:00
freeze_intrinsics.js lib: prefer AsyncIteratorPrototype primordial 2025-07-29 21:54:16 +00:00
heap_utils.js v8: fix missing callback in heap utils destroy 2025-06-30 11:51:40 +00:00
histogram.js perf_hooks: do not expose SafeMap via Histogram wrapper 2025-07-22 16:28:02 +00:00
http.js http: replace startsWith with strict equality 2025-10-30 14:43:31 +00:00
inspector_async_hook.js inspector: skip promise hook in the inspector async hook 2025-02-23 01:07:21 +00:00
inspector_network_tracking.js inspector: add http2 tracking support 2025-08-27 16:25:13 +00:00
js_stream_socket.js http2: fix h2-over-h2 connection proxying 2024-04-08 09:53:18 +00:00
linkedlist.js lib: add trailing commas to more internal files 2023-02-26 11:34:02 +01:00
locks.js worker: implements nits in Web Locks code 2025-07-31 08:14:57 +00:00
mime.js meta: enable jsdoc/check-tag-names rule 2025-07-18 09:28:21 +00:00
navigator.js worker: add web locks api 2025-07-18 07:55:10 -07:00
net.js lib: simplify IPv6 checks in isLoopback() 2025-08-12 11:00:11 +02:00
options.js src: add internal GetOptionsAsFlags 2025-08-16 06:43:49 +00:00
priority_queue.js lib: optimize priority queue 2025-10-04 22:08:00 +02:00
promise_hooks.js tools: add lint rule to keep primordials in ASCII order 2024-04-21 16:53:08 +00:00
querystring.js lib: add trailing commas to more internal files 2023-02-26 11:34:02 +01:00
README.md doc: add note about --expose-internals 2024-09-23 20:22:45 +00:00
repl.js repl: extract and standardize history from both repl and interface 2025-05-28 07:38:39 +00:00
socket_list.js lib: add trailing commas to more internal files 2023-02-26 11:34:02 +01:00
socketaddress.js net: add SocketAddress.parse 2024-12-04 09:29:30 -08:00
stream_base_commons.js stream: relocate the status checking code in the onwritecomplete 2024-09-02 07:29:17 +00:00
timers.js lib: remove redundant destroyHook checks 2025-10-08 12:11:43 +00:00
trace_events_async_hooks.js lib: add trailing commas to more internal files 2023-02-26 11:34:02 +01:00
tty.js tty: treat empty NO_COLOR same as absent NO_COLOR 2025-06-28 15:26:22 +02:00
url.js url: add type checking to urlToHttpOptions() 2025-09-12 12:59:26 +00:00
util.js util: use more defensive code when inspecting error objects 2025-10-20 18:14:39 +00:00
v8_prof_polyfill.js lib: add trailing commas to more internal files 2023-02-26 11:34:02 +01:00
v8_prof_processor.js src: implement natives binding without special casing 2023-06-09 15:32:55 +02:00
validators.js meta: enable jsdoc/check-tag-names rule 2025-07-18 09:28:21 +00:00
vm.js meta: enable jsdoc/check-tag-names rule 2025-07-18 09:28:21 +00:00
wasm_web_api.js lib: add trailing commas to more internal files 2023-02-26 11:34:02 +01:00
watchdog.js lib: add trailing commas to more internal files 2023-02-26 11:34:02 +01:00
webidl.js lib: prefer symbol to number in webidl type function 2024-11-07 23:21:50 +00:00
webstorage.js lib: throw from localStorage getter on missing storage path 2025-10-31 19:48:29 +00:00
worker.js worker: add heap profile API 2025-09-23 12:41:47 +00:00

Internal Modules

The modules located in lib/internal directory are exclusively meant for internal usage within the Node.js core. They are not intended to be accessed via user modules require(). These modules may change at any point in time. Relying on these internal modules outside the core is not supported and can lead to unpredictable behavior.

In certain scenarios, accessing these internal modules for debugging or experimental purposes might be necessary. Node.js provides the --expose-internals flag to expose these modules to userland code. This flag only exists to assist Node.js maintainers with debugging internals. It is not meant for use outside the project.