Hacker News new | ask | show | jobs
by vmfunction 1107 days 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

On the script site use: const url = new URL(import.meta.url); console.log(`${url.searchParams.get("name")`);

1 comments

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);
The 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.