TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Require(esm) in Node.js

34 点作者 tilt大约 1 年前

7 条评论

dimgl大约 1 年前
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&#x27;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:&#x2F;&#x2F;github.com&#x2F;privatenumber&#x2F;tsx">https:&#x2F;&#x2F;github.com&#x2F;privatenumber&#x2F;tsx</a>
评论 #39789275 未加载
paulddraper大约 1 年前
&gt; 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&#x2F;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.)
jauntywundrkind大约 1 年前
It&#x27;s all just so extra crazy because <a href="https:&#x2F;&#x2F;github.com&#x2F;standard-things&#x2F;esm">https:&#x2F;&#x2F;github.com&#x2F;standard-things&#x2F;esm</a> has just worked for so so long. The intense module discussions kept happening, about why it wouldn&#x27;t work or how it would blow up, but standard-things&#x2F;esm was already out &amp; working great.
sam_goody大约 1 年前
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&#x27;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:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;require-esm-in-cjs" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;require-esm-in-cjs</a>
评论 #39785816 未加载
dimgl大约 1 年前
&gt; 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&#x2F;communication with the standard bodies and those who didn’t.<p>By the way, we&#x27;ve been saying this for years. And anyone who pointed out how ridiculous this was got ostracized by Node devs. It&#x27;s just baffling how this was handled.
xeckr大约 1 年前
I really wish ECMA just ran with the Node.js require instead of unnecessarily creating a new standard. Maybe one day we&#x27;ll see interchangeable use of require&#x2F;import.<p>One has to wonder about the total number of hours wasted debugging issues that trace their origin to ECMA&#x27;s decision.
评论 #39787645 未加载
评论 #39792670 未加载
lloydatkinson大约 1 年前
&gt; 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?
评论 #39782955 未加载