Convert all .js files to ESM from CommonJS

Ed H AHSAA Blog
Ed's Blog Index & Contents

Dec 17, 2024 3:35

Eleventy version 3 introduces ESM. eleventy v1 and v2 used commonJS. CommonJs uses require statement and module.export type syntax. while ESM uses import from or export default syntax. I changed all my *.js files to use ESM style and then added

Changed all *.js files from commonJS to ESM

module.exports = {something here}; 

** to ESM style

export default {}
import from

took a few hours to figure out the new syntax and find all the instances of my javascript data files.

added "type": "module" to the package.json config file to tell eleventy to process all .js files as ESM not commonJs

that uncovered 3 more errors of .js files that I had forgotten to convert