How to use ES6 modules from dev tools console

Timmmm picture Timmmm · Sep 29, 2018 · Viewed 11.7k times · Source

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.

Answer

Kin picture Kin · Dec 29, 2018

You can use dynamic import within Chrome's console.

import('path/to/module.js').then(m => module = m)

// [doSomething] is an exported function from [module.js].
module.doSomething()