4 ms·
That might sound irrelevant on the face of it, but it has very real consequences. For example, the following pattern is simply not possible with ESM: c
by djrockstar1 5y ago
That might sound irrelevant on the face of it, but it has
very real consequences. For example, the following pattern
is simply not possible with ESM:
const someInitializedModule = require("module-name")
(someOptions);
Or how about this one? Also no longer possible:
const app = express();
// ...
app.use("/users", require("./routers/users"));
Configurable modules and lazily loaded imports are both missing from the ES Modules spec.
- Ginden 5y ago> lazily loaded imports are both missing from the ES Modules spec. What do you mean?
- wereHamster 5y agoimport someModule from "module-name" const someInitializedModule = someModule(someOptions) A bit longer, but meh… const app = express(); app.use("/users", (await import("./routers/users")).default); top-level await is a thing now Actually, the first example could be rewritten as const someInitializedModule = (await import("module-name")).default(someOptions); That «simply not possible» statement is simply not true
- presentation 5y agoOr don’t even bother with the awaited import and instead import it at the top of the file, I fail to see why this is even an issue lol
- bricss 5y agodynamic imports for that matter, or: import { createRequire } from 'module'; const require = createRequire(import.meta.url); const cjsOrJson = require('./somewhat/module/pathway');