* Check invariants on a cached module job when require()'d from ESM. * @param {string} specifier The first parameter of require(). * @param {string} url URL of the module being required. * @param {string|undefined} parentURL URL of the module calling require(). * @param {ModuleJobBase} j
(specifier, url, parentURL, job)
| 354 | * @param {ModuleJobBase} job The cached module job. |
| 355 | */ |
| 356 | #checkCachedJobForRequireESM(specifier, url, parentURL, job) { |
| 357 | // This race should only be possible on the loader hook thread. See https://github.com/nodejs/node/issues/59666 |
| 358 | if (!job.module) { |
| 359 | throw new ERR_REQUIRE_ESM_RACE_CONDITION(url, parentURL, this.isForAsyncLoaderHookWorker); |
| 360 | } |
| 361 | // This module is being evaluated, which means it's imported in a previous link |
| 362 | // in a cycle. |
| 363 | if (job.module.getStatus() === kEvaluating) { |
| 364 | const parentFilename = urlToFilename(parentURL); |
| 365 | let message = `Cannot import Module ${specifier} in a cycle.`; |
| 366 | if (parentFilename) { |
| 367 | message += ` (from ${parentFilename})`; |
| 368 | } |
| 369 | throw new ERR_REQUIRE_CYCLE_MODULE(message); |
| 370 | } |
| 371 | |
| 372 | // Otherwise the module could be imported before but the evaluation may be already |
| 373 | // completed (e.g. the require call is lazy) so it's okay. We will return the |
| 374 | // job and check asynchronicity of the entire graph later, after the |
| 375 | // graph is instantiated. |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Load a module and translate it into a ModuleWrap for require(esm). |
no test coverage detected