Appreciate this change. The ESM stuff is nightmarishly esoteric. Most recently I ran into ERR_REQUIRE_ESM while trying to write Playwright E2E tests that import from other packages in our monorepo.<p>I really think the way ESM was handled hurt Node.js a lot. Couple this with the introduction of TypeScript and complexity in the Node.js ecosystem skyrocketed. I've lost so many hours on this.<p>Thankfully libraries like esbuild exist (and by extension `tsx` which uses esbuild under the hood). <a href="https://github.com/privatenumber/tsx">https://github.com/privatenumber/tsx</a>
> After dwelling on this a bit, I think the reason why the synchronicity of ESM didn’t lead to a synchronous require(esm) in Node.js sooner was more cultural than technical. There seemed to be a silo problem between those who worked on the ESM implementation in Node.js/communication with the standard bodies and those who didn’t.<p>Must be something like that.<p>This never made a lick of sense.<p>(At the very least for synchronous modules.)
It's all just so extra crazy because <a href="https://github.com/standard-things/esm">https://github.com/standard-things/esm</a> has just worked for so so long. The intense module discussions kept happening, about why it wouldn't work or how it would blow up, but standard-things/esm was already out & working great.
Awesome that this is in Node.<p>I created require-esm-in-cjs[1] two years ago when I needed to require ESM modules in a commonJS (regular legacy) page.<p>It is only a few bytes long and is simple - it effectively causes ESM modules to load synchronously by checking every 100ms if the JS has loaded before allowing the page to continue.<p>I have been meaning to improve it, such as adding a timeout and whatnot but never got around to it (it is good enough for my needs) - but always thought it was odd that something so (relatively) simple to hack around and so low in the stack can not be supported natively.<p>It gets a fair amount of downloads even though it doesn't get much visibility so I guess I am not the only one who felt the need. But native is MUCH better!<p>[1]: <a href="https://www.npmjs.com/package/require-esm-in-cjs" rel="nofollow">https://www.npmjs.com/package/require-esm-in-cjs</a>
> After dwelling on this a bit, I think the reason why the synchronicity of ESM didn’t lead to a synchronous require(esm) in Node.js sooner was more cultural than technical. There seemed to be a silo problem between those who worked on the ESM implementation in Node.js/communication with the standard bodies and those who didn’t.<p>By the way, we've been saying this for years. And anyone who pointed out how ridiculous this was got ostracized by Node devs. It's just baffling how this was handled.
I really wish ECMA just ran with the Node.js require instead of unnecessarily creating a new standard. Maybe one day we'll see interchangeable use of require/import.<p>One has to wonder about the total number of hours wasted debugging issues that trace their origin to ECMA's decision.
> Recently I landed experimental support for require()-ing synchronous ES modules in Node.js, a feature that has been long overdue.<p>Oh come on, overdue for what purpose? Digging Node out of another Node created hole?