nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
105.27k stars 28.52k forks source link

Tracking issue: require(esm) #52697

Open joyeecheung opened 2 months ago

joyeecheung commented 2 months ago

Before it's unflagged

Before it is promoted to be stable:

Nice-to-haves:

RedYetiDev commented 2 months ago

(Slightly unrelated) Maybe we should add a new tracker label to the repo?

GeoffreyBooth commented 2 months ago

@nodejs/loaders

jakebailey commented 2 months ago

I just wanted to note it here, but it would be super super awesome if (once stable) this were backported to Node 20/22 or even Node 18 if still in support. I'd love to be able to propose a change to switch TypeScript to ESM (given I have it working without breaking CJS consumers), but the time horizon of Node 22 being the oldest supported version is pretty daunting.

It also seems like there is a hacky way using multiple entrypoints that could allow for TS to grab Node's builtins conditionally without #52599/#52762, though none of that is possible without require(ESM), of course.

Even without TypeScript's use case, I think the feature itself is a really important one for the ecosystem. Backporting would really make ESM changeovers a lot less painful.

Andarist commented 2 months ago

IIRC from some Twitter threads - there is a plan to backport this once the feature stabilizes.