Files
node/test/fixtures/es-module-loaders/not-found-assert-loader.mjs
T
Antoine du Hamel d1ef6aa2db esm: use import attributes instead of import assertions
The old import assertions proposal has been
renamed to "import attributes" with the follwing major changes:

1. The keyword is now `with` instead of `assert`.
2. Unknown assertions cause an error rather than being ignored,

This commit updates the documentation to encourage folks to use the new
syntax, and add aliases for module customization hooks.

PR-URL: https://github.com/nodejs/node/pull/50140
Fixes: https://github.com/nodejs/node/issues/50134
Refs: https://github.com/v8/v8/commit/159c82c5e6392e78b9bba7161b1bed6e23758984
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2023-10-14 03:52:38 +00:00

17 lines
553 B
JavaScript

import assert from 'node:assert';
// A loader that asserts that the defaultResolve will throw "not found"
// (skipping the top-level main of course, and the built-in ones needed for run-worker).
let mainLoad = true;
export async function resolve(specifier, { importAttributes }, next) {
if (mainLoad || specifier === 'path' || specifier === 'worker_threads') {
mainLoad = false;
return next(specifier);
}
await assert.rejects(next(specifier), { code: 'ERR_MODULE_NOT_FOUND' });
return {
url: 'node:fs',
importAttributes,
};
}