3 ms·
> loading of the underlying module to be performed fully asynchronously Right now, Node uses require(). What he means here is that while this does return a Pro
by pitaj 10y ago
> loading of the underlying module to be performed fully asynchronously
Right now, Node uses require(). What he means here is that while this does return a Promise, the underlying loading of the module doesn't have to be asynchronous, you could just do something like this:
function import(module) {
return Promise.resolve(require(module));
}
Which would fill the requirement of returning a Promise, but would actually load the module using the normal synchronous means.
> I thought that was an unusually elegant solution in this community.
The biggest issue with unambiguous module syntax is that, since you have to parse modules before finishing the resolution, it could drastically lengthen startup time.
- mstade 10y agoThanks for the clarification! Regarding parsing modules – that's a fair point but surely this has to be done anyway? For ESMs you have to parse them to build the binding map, and for CJS you have to parse to evaluate; either way the modules get parsed at some point so why would this in any way be an additional overhead?