Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 221
Timmmm Avatar asked Sep 29 '18 15:09

Timmmm


1 Answers

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() 
like image 79
Kin Avatar answered Sep 23 '22 15:09

Kin