Re:Node Modules at War: Why CommonJS and ES Modules Can’t Ge...
by foreigner on Thursday August 06, 2020 @02:14AM
(#24068542)
The description of how require() works is not quite correct. Node does not always fully initialize the dependency module before returning from require(). It can't work that way, because Node allows circular require() dependencies. Try it!
[ Parent
| on HN ]
Re:Node Modules at War: Why CommonJS and ES Modules Can’t Ge...
by dsun179 on Thursday August 06, 2020 @04:05AM
(#24068997)
The reason is not correct. Nodejs cache the require lot and so circular dependencies can work without returning half finished loads.
Re:Node Modules at War: Why CommonJS and ES Modules Can’t Ge...
by foreigner on Thursday August 06, 2020 @06:38AM
(#24069717)
Nodejs does cache the results of require(), but that doesn't help with this problem. Example: https://repl.it/repls/SwiftOlivedrabBrace
Re:Node Modules at War: Why CommonJS and ES Modules Can’t Ge...
by dimgl on Thursday August 06, 2020 @02:34AM
(#24068626)
> Node does not always fully initialize the dependency module before returning from require().
Unsure what this means. The only reason this happens is because an unfinished copy is provided to the dependency that is causing a circular reference.
Re:Node Modules at War: Why CommonJS and ES Modules Can’t Ge...
by Doxin on Thursday August 06, 2020 @02:49AM
(#24068698)
It means you can get a half-initialized module back from a require() call.