Static GitHub Issues

[1935] Support for .mjs files and native ESM

prev: SSR vs. static site generation
next: How to get access to vuex/vue-router in plugins js-files

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
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This feature request is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c1727">#c1727</a>)</em></sub></div>