Node and ESM module resolution
The short version
- Include a
"type": "module"
in thepackage.json
for the imported module.
OR
- Set the file extension of the imported module to
.mjs
.
The longer version
I was a bit confused about this, so created a repo to shore up my understanding: github.com/m-allanson/node-esm-resolution.
If you’re writing a package and want to export CommonJS and ESM versions, here’s a good overview by Dr. Axel Rauschmayer.
And some further information, including potential pitfalls of dual-format packages in Node’s docs.