node/test/fixtures/es-module-loaders
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
..
never-settling-resolve-step esm: use sync loading/resolving on non-loader-hook thread 2025-10-31 20:45:10 +00:00
node_modules
assertionless-json-import.mjs
builtin-named-exports-loader.mjs
builtin-named-exports.mjs
byop-dummy-loader.mjs
example-loader.mjs
hook-resolve-type-loader.mjs
hook-resolve-type.mjs
hooks-custom.mjs
hooks-initialize-port.mjs
hooks-initialize.mjs
hooks-input.mjs
http-loader.mjs
js-as-esm.js
loader-dep.js
loader-edge-cases.mjs
loader-invalid-format.mjs
loader-invalid-url.mjs
loader-load-bad-next-context.mjs
loader-load-bad-next-url.mjs
loader-load-dynamic-import.mjs
loader-load-foo-or-42.mjs
loader-load-impersonating-next-url.mjs
loader-load-incomplete.mjs
loader-load-next-modified.mjs
loader-load-null-return.mjs
loader-load-passing-modified-context.mjs
loader-load-passthru.mjs
loader-load-receiving-modified-context.mjs
loader-log-args.mjs
loader-resolve-42.mjs
loader-resolve-bad-next-context.mjs
loader-resolve-bad-next-specifier.mjs
loader-resolve-dynamic-import.mjs
loader-resolve-foo.mjs
loader-resolve-incomplete.mjs
loader-resolve-multiple-next-calls.mjs
loader-resolve-next-modified.mjs
loader-resolve-null-return.mjs
loader-resolve-passing-modified-context.mjs
loader-resolve-passthru.mjs
loader-resolve-receiving-modified-context.mjs
loader-resolve-shortcircuit.mjs
loader-resolve-strip-xxx.mjs
loader-resolve-strip-yyy.mjs
loader-shared-dep.mjs
loader-this-value-inside-hook-functions.mjs
loader-unknown-builtin-module.mjs
loader-with-custom-condition.mjs
loader-with-dep.mjs
loader-with-too-many-args.mjs
missing-dynamic-instantiate-hook.mjs
mock-loader.mjs
mock.mjs
module-named-exports.mjs
not-found-assert-loader.mjs
preset-cjs-source.mjs
register-loader.cjs
register-loader.mjs
register-programmatically-loader-load.mjs
register-programmatically-loader-resolve.mjs
string-sources.mjs
syntax-error.mjs
thenable-load-hook-rejected-no-arguments.mjs
thenable-load-hook-rejected.mjs
thenable-load-hook.mjs
throw-undefined.mjs