Open
Description
- Version: all LTS
- Platform: all
- Subsystem: module, esm, policy
What steps will reproduce the bug?
Produce an error in the lines:
node/lib/internal/modules/esm/module_job.js
Lines 116 to 118 in 5f2bb88
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?
See the original error with linkage, preferably decorated properly.
What do you see instead?
The error that was thrown while attempting to decorate the original error.
Additional information
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:
$ 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:
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)