3 ms·
He isn't talking about named exports; he is talking about immediate invocation of the imported module. require("module-name")(someOptions) is instead repre
by azangru 3y ago
He isn't talking about named exports; he is talking about immediate invocation of the imported module.
require("module-name")(someOptions)
is instead represented as
import { someModule as someModuleFactory } from 'module-name';
const someInitializedModule = someModuleFactory(someOptions);
- WorldMaker 3y agoThe most direct translation is something like: (await import("module-name")).default(someOptions) The biggest issue is import() is async and module proxies aren't allowed to be directly callable so you need to pick an export from the other module to call. But `default` is an appropriate export to call, even if there's no nice shorthand for default imports in the import() case (as there is syntax sugar in the import keyword case for default). Neither of those things seem like deal breakers to me, and have very good reasons for why they are the way they are.