Converting a Node Project from CommonJS to ESM
I had a small JavaScript project (deployed via AWS lambda, which I’ll write about later on). I needed to add a very simple package to the project—detect-cloudflare—which sent me down a deep rabbit hole: My project was written years ago using CommonJS (i.e. require). cloudflare-detect included a bunch of packages for a very simple task, which bothers me. Plus, the IP address ranges were out of date and the package hadn’t been updated in years, I decided I wanted to update it. Should be easy, right? (this is never a good thing for an engineer to say) I updated the project and got all of the tests passing without too much effort. Nice! When I went to use the newly refactored package in my project it failed with this error. Uh oh…
Continue Reading