Skip to content
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

ESM Linkage Error Decoration can throw errors subsuming the original #37812

Open
bmeck opened this issue Mar 19, 2021 · 0 comments
Open

ESM Linkage Error Decoration can throw errors subsuming the original #37812

bmeck opened this issue Mar 19, 2021 · 0 comments
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. module Issues and PRs related to the module subsystem. policy Issues and PRs related to the policy subsystem.

Comments

@bmeck
Copy link
Member

bmeck commented Mar 19, 2021

  • Version: all LTS
  • Platform: all
  • Subsystem: module, esm, policy

What steps will reproduce the bug?

Produce an error in the lines:

const childFileURL =
await this.loader.resolve(childSpecifier, parentFileUrl);
const format = await this.loader.getFormat(childFileURL);
either by ESM loader or policy.

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)
@DerekNonGeneric DerekNonGeneric added esm Issues and PRs related to the ECMAScript Modules implementation. module Issues and PRs related to the module subsystem. policy Issues and PRs related to the policy subsystem. labels Mar 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. module Issues and PRs related to the module subsystem. policy Issues and PRs related to the policy subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants