Skip to content

module: expose resolveLoadAndCache API #55756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions doc/api/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,71 @@ resolution and loading behavior. See [Customization hooks][].

This feature requires `--allow-worker` if used with the [Permission Model][].

### `module.resolve(specifier, parentURL[, importAttributes]])`

<!-- YAML
added: REPLACEME
-->

> Stability: 1 - Experimental

* `specifier` {string|URL} Module to resolve and load; this should be
the same string that would be passed to `import()`, except that if it is
relative, it is resolved relative to `parentURL`.
* `parentURL` {string|URL|undefined} The base URL to resolve `specifier` from,
such as `import.meta.url`.
* `importAttributes` {Object} **Default:** an empty object.
* Returns: {Promise} fulfills with a string containing the full URL of the
potential module corresponding to the given specifier.

Analogous to `import.meta.resolve`, but asynchronous, accessible from CommonJS
modules, and with additional parameters.

### `module.load(url[, importAttributes[, conditions]]])`

<!-- YAML
added: REPLACEME
-->

> Stability: 1 - Experimental

* `url` {string|URL|undefined} The URL of the module to load.
* `importAttributes` {Object} **Default:** an empty object.
* `conditions` {Array}
* Returns: {Promise} fulfills with an object with the following properties:
* `url` {string} The absolute URL for that module
* `format` {string} The format this module will be parsed as.
* `source` {null|TypedArray}

This API tells you how the passed URL would be loaded by the module loader if
it was imported in the current process – or, if `conditions` is provided, how
would it be loaded in a process with such configuration.

### `module.resolveLoadAndCache(specifier, parentURL[, importAttributes[, conditions]]])`

<!-- YAML
added: REPLACEME
-->

> Stability: 1 - Experimental

* `specifier` {string|URL} Module to resolve and load; this should be
the same string that would be passed to `import()`, except that if it is
relative, it is resolved relative to `parentURL`.
* `parentURL` {string|URL|undefined} The base URL to resolve `specifier` from,
such as `import.meta.url`.
* `importAttributes` {Object} **Default:** an empty object.
* `conditions` {Array}
* Returns: {Promise} fulfills with an object with the following properties:
* `url` {string} The absolute URL for that module
* `format` {string} The format this module will be parsed as.
* `source` {null|TypedArray}

This API tells you how the passed specifier would be loaded by the module loader if
it was imported from the `parentURL` in the current process – or, if
`conditions` is provided, how would it be loaded in a process with such
configuration.

### `module.registerHooks(options)`

<!-- YAML
Expand Down
40 changes: 39 additions & 1 deletion lib/internal/modules/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
const assert = require('internal/assert');

const { getOptionValue } = require('internal/options');
const { setOwnProperty, getLazy } = require('internal/util');
const { setOwnProperty, getLazy, kEmptyObject } = require('internal/util');
const { inspect } = require('internal/util/inspect');

const lazyTmpdir = getLazy(() => require('os').tmpdir());
Expand Down Expand Up @@ -391,6 +391,41 @@
const constants = { __proto__: null, compileCacheStatus };
ObjectFreeze(constants);

async function resolve(specifier, base, importAttributes = kEmptyObject) {
const cascadedLoader = require('internal/modules/esm/loader').getOrInitializeCascadedLoader();
const { url, format: resolveFormat } = await cascadedLoader.resolve(`${specifier}`, `${base}`, importAttributes);

Check failure on line 396 in lib/internal/modules/helpers.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'resolveFormat' is assigned a value but never used
return url;
}
async function load(url, importAttributes = kEmptyObject, conditions) {

Check failure on line 399 in lib/internal/modules/helpers.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected blank line before this statement
const cascadedLoader = require('internal/modules/esm/loader').getOrInitializeCascadedLoader();
const { format, source } = await cascadedLoader.load(url, {
__proto__: null,
importAttributes,
conditions,
});
return {
__proto__: null,
format,
source,
};
}
async function resolveAndLoad(specifier, base = undefined, importAttributes = kEmptyObject, conditions) {

Check failure on line 412 in lib/internal/modules/helpers.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected blank line before this statement
const cascadedLoader = require('internal/modules/esm/loader').getOrInitializeCascadedLoader();
const { url, format: resolveFormat } = await cascadedLoader.resolve(`${specifier}`, `${base}`, importAttributes);
const { format, source } = await cascadedLoader.load(url, {
__proto__: null,
importAttributes,
format: resolveFormat,
conditions,
});
return {
__proto__: null,
format,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When --experimental-strip-types is enabled and performing this operation on a .ts file, this format may contains commonjs-typescript and module-typescript which are not documented at https://nodejs.org/api/module.html#loadurl-context-nextload as final formats.

I think we should convert commonjs-typescript and module-typescript to commonjs and module respectively. Alternatively, document the other two and make them public.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we probably want to document it, as it's certainly going to be helpful for the ecosystem to know which files are TypeScript

source,
url,
};
}

/**
* Get the compile cache directory if on-disk compile cache is enabled.
* @returns {string|undefined} Path to the module compile cache directory if it is enabled,
Expand All @@ -413,6 +448,9 @@
loadBuiltinModule,
makeRequireFunction,
normalizeReferrerURL,
resolve,
load,
resolveAndLoad,
stringify,
stripBOM,
toRealPath,
Expand Down
10 changes: 9 additions & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,26 @@
enableCompileCache,
flushCompileCache,
getCompileCacheDir,
resolve,
load,
resolveAndLoad,
} = require('internal/modules/helpers');
const {
findPackageJSON,
} = require('internal/modules/package_json_reader');
const { stripTypeScriptTypes } = require('internal/modules/typescript');

Module.register = register;
Module.constants = constants;
Module.enableCompileCache = enableCompileCache;
Module.findPackageJSON = findPackageJSON;
Module.findSourceMap = findSourceMap;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like unrelated changes.

Module.flushCompileCache = flushCompileCache;
Module.getCompileCacheDir = getCompileCacheDir;
Module.register = register;
Module.resolve= resolve;

Check failure on line 34 in lib/module.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Operator '=' must be spaced
Module.load = load;
Module.resolveAndLoad= resolveAndLoad;

Check failure on line 36 in lib/module.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Operator '=' must be spaced
Module.SourceMap = SourceMap;
Module.stripTypeScriptTypes = stripTypeScriptTypes;

// SourceMap APIs
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/typescript/legacy-module/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Legacy TypeScript Module

When `tsconfig.json` is set to `module: "node16"` or any `node*`, the TypeScript compiler will
produce the output in the format by the extension (e.g. `.cts` or `.mts`), or set by the
`package.json#type` field, regardless of the syntax of the original source code.
3 changes: 3 additions & 0 deletions test/fixtures/typescript/legacy-module/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const foo: string = 'Hello, TypeScript!';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const foo: string = 'Hello, TypeScript!';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const foo: string = 'Hello, TypeScript!';
24 changes: 24 additions & 0 deletions test/parallel/test-module-loadmodule-no-typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Flags: --no-experimental-strip-types

'use strict';

require('../common');
const test = require('node:test');
const assert = require('node:assert');
const { pathToFileURL } = require('node:url');
const fixtures = require('../common/fixtures');
const { resolveLoadAndCache } = require('node:module');

const parentURL = pathToFileURL(__filename);

test('should reject a TypeScript module', async () => {
const fileUrl = fixtures.fileURL('typescript/legacy-module/test-module-export.ts');
await assert.rejects(

Check failure on line 16 in test/parallel/test-module-loadmodule-no-typescript.js

View workflow job for this annotation

GitHub Actions / test-macOS

--- stdout --- Test failure: 'should reject a TypeScript module' Location: test/parallel/test-module-loadmodule-no-typescript.js:14:1 AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + Comparison {} - Comparison { - code: 'ERR_UNKNOWN_FILE_EXTENSION' - } at async TestContext.<anonymous> (/Users/runner/work/node/node/node/test/parallel/test-module-loadmodule-no-typescript.js:16:3) at async Test.run (node:internal/test_runner/test:1069:7) at async startSubtestAfterBootstrap (node:internal/test_runner/harness:332:3) { generatedMessage: true, code: 'ERR_ASSERTION', actual: TypeError: resolveLoadAndCache is not a function at assert.rejects.code (/Users/runner/work/node/node/node/test/parallel/test-module-loadmodule-no-typescript.js:18:13) at waitForActual (node:assert:551:21) at Function.rejects (node:assert:686:31) at TestContext.<anonymous> (/Users/runner/work/node/node/node/test/parallel/test-module-loadmodule-no-typescript.js:16:16) at Test.runInAsyncScope (node:async_hooks:214:14) at Test.run (node:internal/test_runner/test:1062:25) at Test.start (node:internal/test_runner/test:959:17) at startSubtestAfterBootstrap (node:internal/test_runner/harness:332:17), expected: [Object], operator: 'rejects' } Command: out/Release/node --no-experimental-strip-types --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /Users/runner/work/node/node/node/test/parallel/test-module-loadmodule-no-typescript.js

Check failure on line 16 in test/parallel/test-module-loadmodule-no-typescript.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04)

--- stdout --- Test failure: 'should reject a TypeScript module' Location: test/parallel/test-module-loadmodule-no-typescript.js:14:1 AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + Comparison {} - Comparison { - code: 'ERR_UNKNOWN_FILE_EXTENSION' - } at async TestContext.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-module-loadmodule-no-typescript.js:16:3) at async Test.run (node:internal/test_runner/test:1069:7) at async startSubtestAfterBootstrap (node:internal/test_runner/harness:332:3) { generatedMessage: true, code: 'ERR_ASSERTION', actual: TypeError: resolveLoadAndCache is not a function at assert.rejects.code (/home/runner/work/node/node/node/test/parallel/test-module-loadmodule-no-typescript.js:18:13) at waitForActual (node:assert:551:21) at Function.rejects (node:assert:686:31) at TestContext.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-module-loadmodule-no-typescript.js:16:16) at Test.runInAsyncScope (node:async_hooks:214:14) at Test.run (node:internal/test_runner/test:1062:25) at Test.start (node:internal/test_runner/test:959:17) at startSubtestAfterBootstrap (node:internal/test_runner/harness:332:17), expected: [Object], operator: 'rejects' } Command: out/Release/node --no-experimental-strip-types --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /home/runner/work/node/node/node/test/parallel/test-module-loadmodule-no-typescript.js

Check failure on line 16 in test/parallel/test-module-loadmodule-no-typescript.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04-arm)

--- stdout --- Test failure: 'should reject a TypeScript module' Location: test/parallel/test-module-loadmodule-no-typescript.js:14:1 AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + Comparison {} - Comparison { - code: 'ERR_UNKNOWN_FILE_EXTENSION' - } at async TestContext.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-module-loadmodule-no-typescript.js:16:3) at async Test.run (node:internal/test_runner/test:1069:7) at async startSubtestAfterBootstrap (node:internal/test_runner/harness:332:3) { generatedMessage: true, code: 'ERR_ASSERTION', actual: TypeError: resolveLoadAndCache is not a function at assert.rejects.code (/home/runner/work/node/node/node/test/parallel/test-module-loadmodule-no-typescript.js:18:13) at waitForActual (node:assert:551:21) at Function.rejects (node:assert:686:31) at TestContext.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-module-loadmodule-no-typescript.js:16:16) at Test.runInAsyncScope (node:async_hooks:214:14) at Test.run (node:internal/test_runner/test:1062:25) at Test.start (node:internal/test_runner/test:959:17) at startSubtestAfterBootstrap (node:internal/test_runner/harness:332:17), expected: [Object], operator: 'rejects' } Command: out/Release/node --no-experimental-strip-types --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /home/runner/work/node/node/node/test/parallel/test-module-loadmodule-no-typescript.js
async () => {
await resolveLoadAndCache(fileUrl, parentURL);
},
{
code: 'ERR_UNKNOWN_FILE_EXTENSION',
}
);
});
49 changes: 49 additions & 0 deletions test/parallel/test-module-loadmodule-typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Flags: --experimental-strip-types

'use strict';

require('../common');
const test = require('node:test');
const assert = require('node:assert');
const { pathToFileURL } = require('node:url');
const fixtures = require('../common/fixtures');
const { resolveLoadAndCache } = require('node:module');

const parentURL = pathToFileURL(__filename);

test('should load a TypeScript module source by package.json type', async () => {
// Even if the .ts file contains module syntax, it should be loaded as a CommonJS module
// because the package.json type is set to "commonjs".

const fileUrl = fixtures.fileURL('typescript/legacy-module/test-module-export.ts');
const { url, format, source } = await resolveLoadAndCache(fileUrl, parentURL);

Check failure on line 19 in test/parallel/test-module-loadmodule-typescript.js

View workflow job for this annotation

GitHub Actions / test-macOS

--- stdout --- Test failure: 'should load a TypeScript module source by package.json type' Location: test/parallel/test-module-loadmodule-typescript.js:14:1 TypeError: resolveLoadAndCache is not a function at TestContext.<anonymous> (/Users/runner/work/node/node/node/test/parallel/test-module-loadmodule-typescript.js:19:41) at Test.runInAsyncScope (node:async_hooks:214:14) at Test.run (node:internal/test_runner/test:1062:25) at Test.start (node:internal/test_runner/test:959:17) at startSubtestAfterBootstrap (node:internal/test_runner/harness:332:17) Test failure: 'should load a TypeScript cts module source by extension' Location: test/parallel/test-module-loadmodule-typescript.js:27:1 TypeError: resolveLoadAndCache is not a function at TestContext.<anonymous> (/Users/runner/work/node/node/node/test/parallel/test-module-loadmodule-typescript.js:31:41) at Test.runInAsyncScope (node:async_hooks:214:14) at Test.run (node:internal/test_runner/test:1062:25) at Test.processPendingSubtests (node:internal/test_runner/test:752:18) at Test.postRun (node:internal/test_runner/test:1191:19) at Test.run (node:internal/test_runner/test:1119:12) at async startSubtestAfterBootstrap (node:internal/test_runner/harness:332:3) Test failure: 'should load a TypeScript mts module source by extension' Location: test/parallel/test-module-loadmodule-typescript.js:39:1 TypeError: resolveLoadAndCache is not a function at TestContext.<anonymous> (/Users/runner/work/node/node/node/test/parallel/test-module-loadmodule-typescript.js:43:41) at Test.runInAsyncScope (node:async_hooks:214:14) at Test.run (node:internal/test_runner/test:1062:25) at Test.processPendingSubtests (node:internal/test_runner/test:752:18) at Test.postRun (node:internal/test_runner/test:1191:19) at Test.run (node:internal/test_runner/test:1119:12) at async Test.processPendingSubtests (node:internal/test_runner/test:752:7) Command: out/Release/node --experimental-strip-types --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /Users/runner/work/node/node/node/test/parallel/test-module-loadmodule-typescript.js

Check failure on line 19 in test/parallel/test-module-loadmodule-typescript.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04)

--- stdout --- Test failure: 'should load a TypeScript module source by package.json type' Location: test/parallel/test-module-loadmodule-typescript.js:14:1 TypeError: resolveLoadAndCache is not a function at TestContext.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-module-loadmodule-typescript.js:19:41) at Test.runInAsyncScope (node:async_hooks:214:14) at Test.run (node:internal/test_runner/test:1062:25) at Test.start (node:internal/test_runner/test:959:17) at startSubtestAfterBootstrap (node:internal/test_runner/harness:332:17) Test failure: 'should load a TypeScript cts module source by extension' Location: test/parallel/test-module-loadmodule-typescript.js:27:1 TypeError: resolveLoadAndCache is not a function at TestContext.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-module-loadmodule-typescript.js:31:41) at Test.runInAsyncScope (node:async_hooks:214:14) at Test.run (node:internal/test_runner/test:1062:25) at Test.processPendingSubtests (node:internal/test_runner/test:752:18) at Test.postRun (node:internal/test_runner/test:1191:19) at Test.run (node:internal/test_runner/test:1119:12) at async startSubtestAfterBootstrap (node:internal/test_runner/harness:332:3) Test failure: 'should load a TypeScript mts module source by extension' Location: test/parallel/test-module-loadmodule-typescript.js:39:1 TypeError: resolveLoadAndCache is not a function at TestContext.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-module-loadmodule-typescript.js:43:41) at Test.runInAsyncScope (node:async_hooks:214:14) at Test.run (node:internal/test_runner/test:1062:25) at Test.processPendingSubtests (node:internal/test_runner/test:752:18) at Test.postRun (node:internal/test_runner/test:1191:19) at Test.run (node:internal/test_runner/test:1119:12) at async Test.processPendingSubtests (node:internal/test_runner/test:752:7) Command: out/Release/node --experimental-strip-types --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /home/runner/work/node/node/node/test/parallel/test-module-loadmodule-typescript.js

Check failure on line 19 in test/parallel/test-module-loadmodule-typescript.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04-arm)

--- stdout --- Test failure: 'should load a TypeScript module source by package.json type' Location: test/parallel/test-module-loadmodule-typescript.js:14:1 TypeError: resolveLoadAndCache is not a function at TestContext.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-module-loadmodule-typescript.js:19:41) at Test.runInAsyncScope (node:async_hooks:214:14) at Test.run (node:internal/test_runner/test:1062:25) at Test.start (node:internal/test_runner/test:959:17) at startSubtestAfterBootstrap (node:internal/test_runner/harness:332:17) Test failure: 'should load a TypeScript cts module source by extension' Location: test/parallel/test-module-loadmodule-typescript.js:27:1 TypeError: resolveLoadAndCache is not a function at TestContext.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-module-loadmodule-typescript.js:31:41) at Test.runInAsyncScope (node:async_hooks:214:14) at Test.run (node:internal/test_runner/test:1062:25) at Test.processPendingSubtests (node:internal/test_runner/test:752:18) at Test.postRun (node:internal/test_runner/test:1191:19) at Test.run (node:internal/test_runner/test:1119:12) at async startSubtestAfterBootstrap (node:internal/test_runner/harness:332:3) Test failure: 'should load a TypeScript mts module source by extension' Location: test/parallel/test-module-loadmodule-typescript.js:39:1 TypeError: resolveLoadAndCache is not a function at TestContext.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-module-loadmodule-typescript.js:43:41) at Test.runInAsyncScope (node:async_hooks:214:14) at Test.run (node:internal/test_runner/test:1062:25) at Test.processPendingSubtests (node:internal/test_runner/test:752:18) at Test.postRun (node:internal/test_runner/test:1191:19) at Test.run (node:internal/test_runner/test:1119:12) at async Test.processPendingSubtests (node:internal/test_runner/test:752:7) Command: out/Release/node --experimental-strip-types --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /home/runner/work/node/node/node/test/parallel/test-module-loadmodule-typescript.js
assert.strictEqual(format, 'commonjs-typescript');
assert.strictEqual(url, fileUrl.href);

// Built-in TypeScript loader loads the source.
assert.ok(Buffer.isBuffer(source));
});

test('should load a TypeScript cts module source by extension', async () => {
// By extension, .cts files should be loaded as CommonJS modules.

const fileUrl = fixtures.fileURL('typescript/legacy-module/test-module-export.cts');
const { url, format, source } = await resolveLoadAndCache(fileUrl, parentURL);
assert.strictEqual(format, 'commonjs-typescript');
assert.strictEqual(url, fileUrl.href);

// Built-in TypeScript loader loads the source.
assert.ok(Buffer.isBuffer(source));
});

test('should load a TypeScript mts module source by extension', async () => {
// By extension, .mts files should be loaded as ES modules.

const fileUrl = fixtures.fileURL('typescript/legacy-module/test-module-export.mts');
const { url, format, source } = await resolveLoadAndCache(fileUrl, parentURL);
assert.strictEqual(format, 'module-typescript');
assert.strictEqual(url, fileUrl.href);

// Built-in TypeScript loader loads the source.
assert.ok(Buffer.isBuffer(source));
});
31 changes: 31 additions & 0 deletions test/parallel/test-module-loadmodule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

require('../common');
const test = require('node:test');
const assert = require('node:assert');
const { pathToFileURL } = require('node:url');
const fixtures = require('../common/fixtures');
const { resolveLoadAndCache } = require('node:module');

const parentURL = pathToFileURL(__filename);

test('should throw if the module is not found', async () => {
await assert.rejects(

Check failure on line 13 in test/parallel/test-module-loadmodule.js

View workflow job for this annotation

GitHub Actions / test-macOS

--- stdout --- Test failure: 'should throw if the module is not found' Location: test/parallel/test-module-loadmodule.js:12:1 AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + Comparison {} - Comparison { - code: 'ERR_MODULE_NOT_FOUND' - } at async TestContext.<anonymous> (/Users/runner/work/node/node/node/test/parallel/test-module-loadmodule.js:13:3) at async Test.run (node:internal/test_runner/test:1069:7) at async startSubtestAfterBootstrap (node:internal/test_runner/harness:332:3) { generatedMessage: true, code: 'ERR_ASSERTION', actual: TypeError: resolveLoadAndCache is not a function at assert.rejects.code (/Users/runner/work/node/node/node/test/parallel/test-module-loadmodule.js:15:13) at waitForActual (node:assert:551:21) at Function.rejects (node:assert:686:31) at TestContext.<anonymous> (/Users/runner/work/node/node/node/test/parallel/test-module-loadmodule.js:13:16) at Test.runInAsyncScope (node:async_hooks:214:14) at Test.run (node:internal/test_runner/test:1062:25) at Test.start (node:internal/test_runner/test:959:17) at startSubtestAfterBootstrap (node:internal/test_runner/harness:332:17), expected: [Object], operator: 'rejects' } Test failure: 'should load a module' Location: test/parallel/test-module-loadmodule.js:23:1 TypeError: resolveLoadAndCache is not a function at TestContext.<anonymous> (/Users/runner/work/node/node/node/test/parallel/test-module-loadmodule.js:25:41) at Test.runInAsyncScope (node:async_hooks:214:14) at Test.run (node:internal/test_runner/test:1062:25) at Test.processPendingSubtests (node:internal/test_runner/test:752:18) at Test.postRun (node:internal/test_runner/test:1191:19) at Test.run (node:internal/test_runner/test:1119:12) at async startSubtestAfterBootstrap (node:internal/test_runner/harness:332:3) Command: out/Release/node --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /Users/runner/work/node/node/node/test/parallel/test-module-loadmodule.js

Check failure on line 13 in test/parallel/test-module-loadmodule.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04)

--- stdout --- Test failure: 'should throw if the module is not found' Location: test/parallel/test-module-loadmodule.js:12:1 AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + Comparison {} - Comparison { - code: 'ERR_MODULE_NOT_FOUND' - } at async TestContext.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-module-loadmodule.js:13:3) at async Test.run (node:internal/test_runner/test:1069:7) at async startSubtestAfterBootstrap (node:internal/test_runner/harness:332:3) { generatedMessage: true, code: 'ERR_ASSERTION', actual: TypeError: resolveLoadAndCache is not a function at assert.rejects.code (/home/runner/work/node/node/node/test/parallel/test-module-loadmodule.js:15:13) at waitForActual (node:assert:551:21) at Function.rejects (node:assert:686:31) at TestContext.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-module-loadmodule.js:13:16) at Test.runInAsyncScope (node:async_hooks:214:14) at Test.run (node:internal/test_runner/test:1062:25) at Test.start (node:internal/test_runner/test:959:17) at startSubtestAfterBootstrap (node:internal/test_runner/harness:332:17), expected: [Object], operator: 'rejects' } Test failure: 'should load a module' Location: test/parallel/test-module-loadmodule.js:23:1 TypeError: resolveLoadAndCache is not a function at TestContext.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-module-loadmodule.js:25:41) at Test.runInAsyncScope (node:async_hooks:214:14) at Test.run (node:internal/test_runner/test:1062:25) at Test.processPendingSubtests (node:internal/test_runner/test:752:18) at Test.postRun (node:internal/test_runner/test:1191:19) at Test.run (node:internal/test_runner/test:1119:12) at async startSubtestAfterBootstrap (node:internal/test_runner/harness:332:3) Command: out/Release/node --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /home/runner/work/node/node/node/test/parallel/test-module-loadmodule.js

Check failure on line 13 in test/parallel/test-module-loadmodule.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04-arm)

--- stdout --- Test failure: 'should throw if the module is not found' Location: test/parallel/test-module-loadmodule.js:12:1 AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + Comparison {} - Comparison { - code: 'ERR_MODULE_NOT_FOUND' - } at async TestContext.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-module-loadmodule.js:13:3) at async Test.run (node:internal/test_runner/test:1069:7) at async startSubtestAfterBootstrap (node:internal/test_runner/harness:332:3) { generatedMessage: true, code: 'ERR_ASSERTION', actual: TypeError: resolveLoadAndCache is not a function at assert.rejects.code (/home/runner/work/node/node/node/test/parallel/test-module-loadmodule.js:15:13) at waitForActual (node:assert:551:21) at Function.rejects (node:assert:686:31) at TestContext.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-module-loadmodule.js:13:16) at Test.runInAsyncScope (node:async_hooks:214:14) at Test.run (node:internal/test_runner/test:1062:25) at Test.start (node:internal/test_runner/test:959:17) at startSubtestAfterBootstrap (node:internal/test_runner/harness:332:17), expected: [Object], operator: 'rejects' } Test failure: 'should load a module' Location: test/parallel/test-module-loadmodule.js:23:1 TypeError: resolveLoadAndCache is not a function at TestContext.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-module-loadmodule.js:25:41) at Test.runInAsyncScope (node:async_hooks:214:14) at Test.run (node:internal/test_runner/test:1062:25) at Test.processPendingSubtests (node:internal/test_runner/test:752:18) at Test.postRun (node:internal/test_runner/test:1191:19) at Test.run (node:internal/test_runner/test:1119:12) at async startSubtestAfterBootstrap (node:internal/test_runner/harness:332:3) Command: out/Release/node --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /home/runner/work/node/node/node/test/parallel/test-module-loadmodule.js
async () => {
await resolveLoadAndCache('nonexistent-module', parentURL);
},
{
code: 'ERR_MODULE_NOT_FOUND',
}
);
});

test('should load a module', async () => {
const fileUrl = fixtures.fileURL('es-modules/cjs.js');
const { url, format, source } = await resolveLoadAndCache(fileUrl, parentURL);
assert.strictEqual(format, 'commonjs');
assert.strictEqual(url, fileUrl.href);

// `source` is null and the final builtin loader will read the file.
assert.strictEqual(source, null);
});
Loading
Loading