Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I could not agree more. In fact, the introduction of ESM has been entirely pernicious, causing more problems, not fewer.

Why? Because there is no importSync(). If that existed, it would be easy to interoperate.



I think it would have been more prudent if Node had chosen to stay closer to Babel compatibility in terms of how it handled ESM + Require. I know there were reasons to break things... but it could have been smoother.


I don't use Babel so I don't know what that means but I do know that I would not be rage-typing if they had simply made importSync().


Why do that when everyone can install any one 1 of 10 third party modules… <_< >_>


Why do you want an `importSync()`?

You could achieve the same thing with a bunch of `import()` calls, but I'm not sure why you'd want to when you can just use the `import` keyword instead.


I have a ton of projects and a huge amount of utilities and such, that all use CJS.

You cannot just use 'import' if you also use CJS. To use 'import', it must be an ESM module and the you cannot use require() to access CJS utilities.

In CJS code, one can use import() to bring in ESM modules but, import() is asynchronous. The problem is that I have a lot of code that is not asynchronous. To add an asynchronous function requires substantial rewriting that I am rarely willing to do.

If, in addition to the asynchronous import(), there was a synchronous importSync(), I could use ESM modules any time I want. That would allow me to...

1) Use and support new utilities that are ESM.

2) Write new utilities that are ESM. Presently, I always target CJS because that's what I have to use.

I have read that there is a new version of NodeJS that supports using require() for ESM modules. That will be a huge, huge, huge improvement although I would prefer importSync() so that it was clear when I was using an ESM module. Even so, I will take it.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: