Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should I prefer ES modules to CommonJS? #2267

Closed
kimamula opened this issue Nov 2, 2019 · 4 comments
Closed

Should I prefer ES modules to CommonJS? #2267

kimamula opened this issue Nov 2, 2019 · 4 comments

Comments

@kimamula
Copy link

kimamula commented Nov 2, 2019

  • Node.js Version: 12 and newer
  • OS: any
  • Scope (install, code, runtime, meta, other?): other
  • Module (and version) (if relevant): -

Now that --experimental-modules is to be unflagged in this month in v13, which is the preferable module system to be used in Node.js, ES modules or CommonJS?

People developing universal Web apps and have been using ES modules for better bundler support may find it is beneficial that they no longer need to transpile their code from ES modules to CommonJS for Node.js.
From performance point of view, it might be possible that the static nature of ES modules provides with some benefit over CommonJS, though I'm not sure.

Another question is that is there any plan or discussion for dropping support for CommonJS?
I found some implication for this (for example, one maintainer said "what a future Node would be like where CommonJS were deprecated" in nodejs/modules#318), but could not have found any official announcement.

@tniessen
Copy link
Member

It depends. If you are writing an application and are happy with using the latest Node.js version, using ESM might be a good idea.

However, dropping the flag for ESM does not mean that it will remain unchanged, and it has not been tested to the same degree as CommonJS. If you intend to publish a package on npm, providing ESM only will make it impossible for people to require() your module.

CommonJS will not be deprecated any time soon, and maybe it will never be.

@devsnek
Copy link
Member

devsnek commented Nov 15, 2019

there are no plans to ever drop support for commonjs.

@kimamula
Copy link
Author

Thanks for your responses.

Though I am satisfied with your answers, I wonder whether I should close this issue as this can be one of FAQ in Node.js and might be worth being kept opened.

@gireeshpunathil
Copy link
Member

closing as answered. @kimamula - If there is documentation improvement that is possible, pls feel free to raise it as a PR. for example: https://nodejs.org/dist/latest-v14.x/docs/api/modules.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants