DEV Community

Discussion on: My impressions after trying to use ES Modules in 2018

d0ruk profile image
Doruk Kutlu


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.