Search code examples
javascriptes6-modules

How to use ES6 modules from dev tools console


As far as I understand it, if I create an ES6 module, I can only import it from code that is itself a module. This means non-module code, i.e. inline Javascript, or the Chrome dev tools console can never access code that is in a module.

Is that true? Is there any way around this because it seems like a fairly extreme limitation.


Solution

  • You can await a dynamic import within Chrome's console:

    const Module = await import('./path/to/module.js')
    Module.doSomething()
    

    That dynamic import is roughly equivalent to:

    import * as Module from './path/to/module.js';
    Module.doSomething()