Don't forget to ask Babel to compile .mjs files

twitter logo github logo ・1 min read

I spent several hours trying to understand why Babel wasn't transpiling const statements in Jeremy Wagner's yall.js library.

It was because the actual filename is yall.mjs, and I hadn't configured Babel to handle that extension.

The correct test configuration ended up being as follows:

test: /\.(m?j|t)s$/,

Or, if you don't need TypeScript:

test: /\.m?js$/,

Suffer me not to ponder the ills and advantages of the .mjs extension. That's for smarter people.

But since some folks do use that extension, it's probably worth updating your Babel config and related documentation/tutorials.

twitter logo DISCUSS
Classic DEV Post from Nov 5 '18

What are you not interested in learning?

What pieces of technology are you not interested in learning and why?

Michael Crenshaw profile image
I'm a software engineer, passionate about clean code and #webperf

dev.to now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️