ES Modules (ESM) and Gatsby
gatsby-node in ESM syntax.
This feature was added in
- A Gatsby project set up with
email@example.com later. (Need help creating one? Follow the Quick Start)
Generally speaking you need to follow the official standard as explained in the Node.js documentation.
gatsby-config.mjs file. Here’s an example
gatsby-config using ESM syntax:
gatsby-node.mjs file and use any of the Node APIs as usual. Here’s an example
gatsby-node using ESM syntax:
exportsyntax instead of
File extensions in imports are mandatory
You can replicate the
You can replicate
Here’s how you’d migrate a
gatsby-config.js file to
The TypeScript variants of
gatsby-nodedo not support ESM yet. We plan on adding support in a future minor release by using the
.mtsextension. If you have questions or suggestions about this, please go to our ESM in Gatsby files umbrella discussion.
However, you can use Type Hinting in the meantime.
The ESM in Gatsby files umbrella discussion is also the right place for any questions about the