gatsby-config/node.js doesn't support ESM import/export
See original GitHub issueSummary
Node v14 is out and with it the removal of the Experimental Modules warning! 🎉
I installed it, added "type": "module"
to package.json
, used export default
in gatsby-config.js
and took the default starter for a spin. This is what I got:
Error: [ERR_REQUIRE_ESM]: Must use import to load ES Module: gatsby-config.js require() of ES modules is not supported. require() of gatsby-config.js from node_modules/gatsby/dist/bootstrap/get-config-file.js is an ES module file as it is a .js file whose nearest parent package.json contains “type”: “module” which defines all .js files in that package scope as ES modules. Instead rename gatsby-config.js to end in .cjs, change the requiring code to use import(), or remove “type”: “module” from package.json.
Sounds like Gatsby, specifically gatsby/dist/bootstrap/get-config-file.js
, stands in the way of using ESM import/export syntax. I think it’s time to make gatsby’s config and node APIs ESM-ready. 🚀
Basic example
export default {
siteMetadata: {
title: `Gatsby Default Starter`,
author: `@gatsbyjs`,
},
plugins: [
`gatsby-plugin-react-helmet`,
// ...
],
}
Motivation
Would be really cool if we could finally use a single import/export system all throughout our Gatsby projects! As the release announcement states:
It is our belief that the current implementation offers a future proof model to authoring ESM modules that paves the path to Universal JavaScript.
If that doesn’t get you excited, you must be in the wrong line of work. 😄
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:37 (23 by maintainers)
Top GitHub Comments
@LekoArts @KyleAMathews Node 16 is out, this is no longer experimental and should be reopened.
Yeah, Gatsby not supporting ESM will become a big problem in the next weeks as people upgrade to the latest
remark
packages, which are full ESM.@LekoArts would recommend the team reopening this one - it should be an issue, not a feature request.
cc @wooorm