Using async / await with dynamic import() for ES6 modules
Approach 2 does not work because accoring to MDN:

import '/modules/my-module.js';


Is how you import a module for Import a module for its side effects only


  Import an entire module for side effects only, without importing anything. This runs the module's global code, but doesn't actually import any values.


So, await import('/path/to/my-module.js'); won't actually import your myfunction1 and myFunction2 for you to use them, however, if you put an IIFE in there, it will be called.

If you don't want to use long names to call your function, you can destructure them :

(async () =&gt; {

  const { myFunction1, myFunction2 } = await import('/path/to/my-module.js');

  myFunction1();
  myFunction2();

})();


Or, call them in my-module.js and just import it and they will get called.

See the answers here for es6 import for side effects meaning.