Hacker News new | ask | show | jobs
by wruza 1622 days ago
Why doesn't nodejs just make modules async?

  // main.js
  const fs = require("fs")
  const foo = await require_async("foo")

  await foo.sleep(1000)

  // other.js
  require("./main.js")

  // RequireError: main.js returned an unsettled promise, use require_async()
Wouldn't that be better of both worlds?
1 comments

Node did make modules async (just ESM modules). They can’t/won’t make CJS async because their synchronous semantics are a guarantee they determined not to break well before ESM. If you want async modules, ESM is the solution for that.
ESM will be the solution to that, when all the major toolchains catch up. I wouldn't sell this future short, but we aren't there yet either.
I agree but I think we’re there (if kicking a bit and screaming a bit).