-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Closed
Labels
esmIssues and PRs related to the ECMAScript Modules implementation.Issues and PRs related to the ECMAScript Modules implementation.
Description
I'm writing custom loader for esm modules and encountered problem.
- Inside loader I import module A
- I use loader to load module B which also uses module A.
- Path to module A is correctly resolved
- In loader module A is correctly loaded but in B its value is undefined.
- Removing module A from loader "fixes" problem.
I bypass problem by keeping track of what modules are used in loader and when one of them is requested I use dynamicInstantiate
hook.
Minimal code for issue looks like this:
loader.mjs
import express from 'express'; // same module
export async function resolve(specifier, parentModuleURL, defaultResolver) {
return defaultResolver(specifier, parentModuleURL);
}
issue.mjs
import express from 'express'; // same module
import assert from 'assert';
assert(express);
command
node --experimental-modules --loader ./loader.mjs ./issue.mjs
expected
(node:8534) ExperimentalWarning: The ESM module loader is experimental.
actual
(node:8534) ExperimentalWarning: The ESM module loader is experimental.
{ AssertionError [ERR_ASSERTION]: undefined == true
at file:///home/bartek/Projekty/github/issues/issue.mjs:4:1
at ModuleJob.run (internal/loader/ModuleJob.js:96:14)
at <anonymous>
generatedMessage: true,
name: 'AssertionError [ERR_ASSERTION]',
code: 'ERR_ASSERTION',
actual: undefined,
expected: true,
operator: '==' }
- Version: v.9.2.0
- Platform: Linux 4.13.0-16-generic Ubuntu 17.10 x86_64
Metadata
Metadata
Assignees
Labels
esmIssues and PRs related to the ECMAScript Modules implementation.Issues and PRs related to the ECMAScript Modules implementation.