DEV Community

You Should be Using esm

Benny Powers 🇮🇱🇨🇦 on September 16, 2018

tl;dr: You can use JavaScript modules in node today without transpiling, just npm -S esm and run your app with node -r esm foo.js. add "...
Collapse
 
codevault profile image
Sergiu Mureşan

Babel is also a very good way to scare beginners from using latest JS. Backwards compatibility is important but there isn't a need to include it in every single tutorial out there. Let people get a taste of new JS then introduce them to Babel, especially now when most up-to-date browsers support it.

Collapse
 
defiance profile image
Defiance Black • Edited

I can attest to this. My first dev foray was into JS and while I was impressed by the breadth of the ecosystem and the enthusiasm of its torch-bearers, I quickly came to find myself in a sea of chaos.

Sea of Chaos is my title for JS because something that has been around for so long should not be nearly so complicated... all to support versions of browsers that less than 5% of people use.

TypeScript looks nice... but Transcrypt has always looked better since embracing Python.

Collapse
 
codevault profile image
Sergiu Mureşan

And I thought that CoffeeScript was the closest to Python. Good find!

Collapse
 
bennypowers profile image
Benny Powers 🇮🇱🇨🇦

Well put

Collapse
 
bennypowers profile image
Benny Powers 🇮🇱🇨🇦

A previous version of this post said that the "esm": "auto" package.json configuration is required for interop, which is incorrect. esm will let you load cjs in modules out of the box, you just need to install and load. The post has been edited.

Collapse
 
nickyhajal profile image
Nicky Hajal

Thanks for the detailed look into this! Dealing with imports is one of the few remaining annoying bits to deal with.

Collapse
 
jsn1nj4 profile image
Elliot Derhay

Not about the content, but tapping the ID links towards the top doesn't seem to work for me. My address bar updates, but nothing else happens.

Collapse
 
bennypowers profile image
Benny Powers 🇮🇱🇨🇦 • Edited

Thanks for the notes. I used GFM-style anchor links, maybe they don't work the same on dev.to.

issue for tracking

Markdown Headers Should Have IDs for Linking #682

Feature Request or Task

When users create headings in markdown, the headings should have ids added to enable linking throughout the document

[tl;dr](#tl-dr)
[The History](#the-history)
[Transpiling](#transpiling)
[The Problem](#the-problem)
[`esm`: A Better Solution](#esm-a-better-solution)
[Summary](#summary)

## tl;dr:
...

## The History
...

## Transpiling
...

## The Problem
...

### The Cost of Transpiling
...

### Principles and Cognitive Load
...

## `esm`: A Simple Solution
...

## Summary
...

User Story / Description

Users with medium-to-long-form content might want to add a table of contents, or a link to a summary or tl;dr.

Definition of Done

When the links in the above snippet work as expected: clicking on one scrolls to the relevant header.

Collapse
 
papaponmx profile image
Jaime Rios

Great, thanks for sharing!

Collapse
 
bjoern_sellnau profile image
Bjoern

ESM is not ready to be used. you can not mock any ESmodules yet, so if you need this functionality you are out of luck.