0

When I'm in debug console for JS (during debug of a given source file), and I try to use a module that was imported in my source file, I get the following error:

Uncaught ReferenceError: myModule is not defined

It seems this will work for importing javascript modules for use in debugging console:

import myModule from '/path/to/module.js';
window.myModule = myModule;

// in the console:
myModule.foo();

(See this answer for more details...)

I want to be able to do this for all of the module imports in a given file, is this easily possible?

Psuedo-code:

for (i = 0; i < num_modules; i++) {
  window[module.name] = modules[i];
}
joshp
  • 706
  • 5
  • 22

1 Answers1

0

I don't believe there is a way to do what you are asking using static ES6 module imports. You could probably create your own method for performing imports by making use of dynamic imports that could then attach the imported modules to the window, or else use a module loader/bundler that allows you to hook into the import process or otherwise exposes the list of imports.

Chris Yungmann
  • 1,079
  • 6
  • 14