Hacker News new | past | comments | ask | show | jobs | submit login

>There are already tons of browser libraries not using the .mjs extension.

Browsers don't care what extension you serve something as, so we can't really directly match that in the default behaviour. What you can do is use a resolve hook to tell node to interpret certain files as esm even when they don't have a `.mjs` extension.

>Not clear to me why just using 'import' makes it a module and 'require' not.

import doesn't "make something a module". if you try to require something that resolves as being esm (rn we check that with .mjs) it will throw, because esm resolution is async and require resolution is sync. You can't require esm but you can import anything.




Why does import have to work with cjs? It doesn't in the browser. Why does require have to work esm?

Why not just have a package up it's major semver and those packages that want to start using it need to import it? That seems no different than the browser. AFAIK you can't import a non-module and you can't non-import a module in the browser or am I wrong?


>Why does import have to work with cjs? It doesn't in the browser. Why does require have to work esm?

`import` doesn't have to work with cjs, but we want to do so because there is so much code in the ecosystem that is cjs.

`require` won't and can't work with esm, because esm resolution is async and require resolution is sync.


Let this be solved in userland through compilers, like everyone already does today. The stubbornness from current node maintainers on this subject is astounding. Years of feedback, like you see in this thread, ‘but-what-if’ and ‘you-dont-get-it’ handwaved away.




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

Search: