DEV Community

Discussion on: Node.js 12 supports ES modules. Do you know the difference between CommonJS and ES2015+ Modules?

Collapse
 
exacs profile image
Carlos Saito • Edited

Yes. You are right. ECMAScript Modules support in Node.js has been almost a myth. When I've written the post (July 2019), it was announced that Node12 will support them.

However, things have been changed and current status is:

  • Node.js 12 supports it if you run it with the --experimental-modules flag (i.e. node --experimental-modules index.js)
  • In Node.js 13 and 14, ESM is supported without flag by default.

Node.js 14 will be in active in LTS (Long Term Support) by October. It is very probable that ESM will be without the flag by default as announced. However, the same was said for Node.js 12 when I've written this (3 months before Node.js 12 reached LTS)

If you want to be 100% sure about Node.js 14 you have to wait until its release in October.

Docs:

Node.js 12: nodejs.org/docs/latest-v12.x/api/e...
Node.js 14: nodejs.org/docs/latest-v14.x/api/e...

I'll edit the post to reflect this. Thanks for your comment!