0

In CommonJS one can run:

const module = require('module')(API_KEY)

In the various ways TC39 / 'ES6' modules (inverted commas as there are are more modules writted in ES6 using CommonJS than this syntax), how can I do the same?

It looks like this isn't possible, ie my only option is:

import moduleSetup from "module";
const module = moduleSetup(API_KEY);
mikemaccana
  • 110,530
  • 99
  • 389
  • 494

1 Answers1

2

ie my only option is

Correct, at least for now.

It may be that the dynamic import proposal will let you do something like the require call, but it's at StageĀ 3 right now. (Of course, if you use them for this, the import won't be statically-analyzable anymore...)

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875