DEV Community

My impressions after trying to use ES Modules in 2018

Jaime Rios on August 22, 2018

TLDR Support is still experimental. Most things work as expected out of the box with a Front End application, but it had a lot of issues with Node...
Collapse
 
bennypowers profile image
Benny Powers ๐Ÿ‡ฎ๐Ÿ‡ฑ๐Ÿ‡จ๐Ÿ‡ฆ

With node it's as easy as -r esm. I have a hard time fathoming why everyone doesn't do this.

As a community, we need to stop letting node's indecision (as justified as it may be) hold us back.

Collapse
 
d0ruk profile image
Doruk Kutlu

Agreed.

How many people know what goes into the bundle when you write


import React, { Component } from "react"

and run it through a transpiler?

How many people (besides the JS disciples) will care if it's .mjs or .js or .esm?

Now, I'm aware that there are proper geniuses in TSC, and they must have discussed this ESM thing over and over. Yet they could only come up with a new extension?

From what I could gather, the main reason for that is "backwards compatibility with commonjs". Compatibility with something that is essentially a collection of hacks?

This is the official spec, not what people made do with in the past. Who thought it was a good idea to use cjs in .js yet esm in .mjs? It should actually be the other way around, if you really want to keep the extension.

FWIW, I think the best way forward was to add something like

"use modules"

at the module level.

Collapse
 
aikar profile image
Daniel Ennis

I'm not a fan of how node is implementing the feature, I think I'll stick to transpiling with babel. Everything works fine with that.

Collapse
 
illusionelements profile image
IllusionElements

Why not just transpile esmodules with babel? Best of both worlds

Collapse
 
papaponmx profile image
Jaime Rios

That is always an option, I wanted to explore the idea of not doing it anymore.