3 ms·
>What we lost is just this >``` const someInitializedModule = require("module-name")(someOptions); ``` That can partially be done such as: import {jason} fro
by vmfunction 3y ago
>What we lost is just this
>``` const someInitializedModule = require("module-name")(someOptions); ```
That can partially be done such as:
import {jason} from 'https://example.com/foo.js?name=jason https://example.com/foo.js?name=jason
On the script site use:
const url = new URL(import.meta.url);
console.log(`${url.searchParams.get("name")`);
- azangru 3y agoHe 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.