Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Imported modules are undefined if also used inside loader #17130

Closed
bartosz-m opened this issue Nov 19, 2017 · 2 comments
Closed

Imported modules are undefined if also used inside loader #17130

bartosz-m opened this issue Nov 19, 2017 · 2 comments
Labels
esm Issues and PRs related to the ECMAScript Modules implementation.

Comments

@bartosz-m
Copy link

I'm writing custom loader for esm modules and encountered problem.

  1. Inside loader I import module A
  2. I use loader to load module B which also uses module A.
  3. Path to module A is correctly resolved
  4. In loader module A is correctly loaded but in B its value is undefined.
  5. 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
@mscdex mscdex added the esm Issues and PRs related to the ECMAScript Modules implementation. label Nov 19, 2017
@guybedford
Copy link
Contributor

Thanks for reporting, I've created a fix at #17131.

guybedford added a commit to guybedford/node that referenced this issue Nov 22, 2017
guybedford added a commit that referenced this issue Nov 28, 2017
PR-URL: #17131
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
@guybedford
Copy link
Contributor

The fix here has been merged.

MylesBorins pushed a commit that referenced this issue Dec 12, 2017
PR-URL: #17131
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
MylesBorins pushed a commit that referenced this issue Dec 12, 2017
PR-URL: #17131
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
MylesBorins pushed a commit that referenced this issue Dec 12, 2017
PR-URL: #17131
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
gibfahn pushed a commit that referenced this issue Dec 19, 2017
PR-URL: #17131
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
gibfahn pushed a commit that referenced this issue Dec 20, 2017
PR-URL: #17131
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
esm Issues and PRs related to the ECMAScript Modules implementation.
Projects
None yet
Development

No branches or pull requests

3 participants