MA

  • Home
  • About

Node and ESM module resolution

March 2021

The short version

  • Include a "type": "module" in the package.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.


  • Next: Five Year Frontend
  • Previous: Updating Dependencies (npm)
RSS Feed Edit this page on Github