Repository: node
Issue: ESM Linkage Error Decoration can throw errors subsuming the original
Labels: module,esm,policy

<!--
Thank you for reporting an issue.

This issue tracker is for bugs and issues found within Node.js core.
If you require more general support please file an issue on our help
repo. https://github.com/nodejs/help


Please fill in as much of the template below as you're able.

Version: output of `node -v`
Platform: output of `uname -a` (UNIX), or output of `"$([Environment]::OSVersion | ForEach-Object VersionString) $(if ([Environment]::Is64BitOperatingSystem) { "x64" } else { "x86" })"` in PowerShell console (Windows)
Subsystem: if known, please specify affected core module name
-->

* **Version**: all LTS
* **Platform**: all
* **Subsystem**: module, esm, policy

### What steps will reproduce the bug?

Produce an error in the lines: https://github.com/nodejs/node/blob/5f2bb885f8027e2789a1fa8679d242162b4a8633/lib/internal/modules/esm/module_job.js#L116-L118 either by ESM loader or policy.

<!--
Enter details about your bug, preferably a simple code snippet that can be
run using `node` directly without installing third-party dependencies.
-->



### How often does it reproduce? Is there a required condition?

Every time.

It is only possible to reproduce with a Loader or Policy.

### What is the expected behavior?

<!--
If possible please provide textual output instead of screenshots.
-->

See the original error with linkage, preferably decorated properly.

### What do you see instead?

<!--
If possible please provide textual output instead of screenshots.
-->

The error that was thrown while attempting to decorate the original error.

### Additional information

<!--
Tell us anything else you think we should know.
-->

This was discovered by @giltayar on https://github.com/giltayar/import-map-to-policy/tree/127d3b068dc1e984708beed3dc5eaf4b116ff68e , which when running `npm run start:node` produced a very confusing:

```console
$ NODE_DEBUG=policy,esm,module node --experimental-policy ./policy.json -- src/node-main.js
POLICY 58628: Manifest contains integrity for resource ./src/node-main.js
POLICY 58628: Manifest contains integrity for resource ./src/write-answer/write-answer.js
POLICY 58628: Manifest contains integrity for scope file:
POLICY 58628: Checking integrity of file:///Users/bfarias/Documents/oss/import-map-to-policy/package.json
(node:58628) ExperimentalWarning: Policies are experimental.
(Use `node --trace-warnings ...` to show where the warning was created)
ESM 58628: Storing file:///Users/bfarias/Documents/oss/import-map-to-policy/src/node-main.js in ModuleMap
POLICY 58628: Checking integrity of file:///Users/bfarias/Documents/oss/import-map-to-policy/src/node-main.js
ESM 58628: Translating StandardModule file:///Users/bfarias/Documents/oss/import-map-to-policy/src/node-main.js
ESM 58628: Storing file:///Users/bfarias/Documents/oss/import-map-to-policy/src/write-answer/write-answer.js in ModuleMap
POLICY 58628: Checking integrity of file:///Users/bfarias/Documents/oss/import-map-to-policy/src/write-answer/write-answer.js
ESM 58628: Translating StandardModule file:///Users/bfarias/Documents/oss/import-map-to-policy/src/write-answer/write-answer.js
ESM 58628: Storing file:///Users/bfarias/Documents/oss/import-map-to-policy/src/answer/answer.js in ModuleMap
POLICY 58628: Checking integrity of file:///Users/bfarias/Documents/oss/import-map-to-policy/src/answer/answer.js
ESM 58628: Translating StandardModule file:///Users/bfarias/Documents/oss/import-map-to-policy/src/answer/answer.js
node:internal/process/esm_loader:74

Error [ERR_MANIFEST_DEPENDENCY_MISSING]: Manifest resource file:///Users/bfarias/Documents/oss/import-map-to-policy/src/node-main.js:1 does not list write-answer as a dependency specifier for conditions: node, import
    at new NodeError (node:internal/errors:329:5)
    at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:821:18)
    at Loader.resolve (node:internal/modules/esm/loader:86:40)
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:117:31)
    at async ModuleJob.run (node:internal/modules/esm/module_job:151:5)
    at async Loader.import (node:internal/modules/esm/loader:166:24)
    at async Object.loadESM (node:internal/process/esm_loader:68:5) {
  code: 'ERR_MANIFEST_DEPENDENCY_MISSING'
}
```

You can note the `:1` that comes from the wrong URL being used when decorating, this caused an error in `resolve` to subsume the original:

```console
file:///Users/bfarias/Documents/oss/import-map-to-policy/src/write-answer/write-answer.js:1
import {theAnswer} from 'answer'
        ^^^^^^^^^
SyntaxError: The requested module 'answer' does not provide an export named 'theAnswer'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:105:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:151:5)
    at async Loader.import (node:internal/modules/esm/loader:166:24)
    at async Object.loadESM (node:internal/process/esm_loader:68:5)
```