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

crenshaw_dev

Michael Crenshaw

Posted on May 17, 2019

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

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$/,
Enter fullscreen mode Exit fullscreen mode

Or, if you don't need TypeScript:

test: /\.m?js$/,
Enter fullscreen mode Exit fullscreen mode

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.

💖 💪 🙅 🚩
crenshaw_dev
Michael Crenshaw

Posted on May 17, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related