Home

Issue: 1935

Support for .mjs files and native ESM

[issue link]

Most of the code in nuxt projects can now be written in modern ES6 syntax. Even more is going to be supported when 8 is next LTS (Such as async/await). However, there are parts currently are not fully ES6 compatible because are being required directly with node and thus depends on pure node functionalities. Also using babel-register to polyfill this gap may introduce many many inconsistencies and perf/stability issues which is not ideal. Current parts which can potentially leverage .mjs:

  • Modules (to be used without any transpiler like roll-up)
  • Server Middleware
  • nuxt.config.js
  • [potentailly] Nuxt.js core source code itself for perf and maintenance reasons

This article is useful for getting started with native esm. Currently, esm support can be enabled behind a flag so we would delay this feature for Nuxt until it gets stable enough.

PS: Any ideas, feedbacks, and contribution are welcome. our only limitation is that PRs should target v2 as this is almost breaking change in the entire ecosystem.

XREFs:

  • #1912
  • #2087
This feature request is available on Nuxt.js community (#c1727)