rewrite gatsby-config & gatsby-node with node 11's experimental ECMAScript modules
See original GitHub issueHas anyone tried replacing module.exports
/require()
in gatsby-config.js
and/or gatsby-node.js
with the experimental import
/export
syntax introduced in node v11.10.1? I’m interested in advice on how to make the transition, whether or not I should wait and if there are any limitations.
Issue Analytics
- State:
- Created 5 years ago
- Comments:14 (6 by maintainers)
Top Results From Across the Web
gatsby-config/node.js doesn't support ESM import/export #23705
Instead rename gatsby-config.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from package.json.
Read more >Gatsby Config API
Plugins are Node.js packages that implement Gatsby APIs. The config file accepts an array of plugins. Some plugins may need only to be...
Read more >Gatsby Changelog | 5.3.0
The ECMAScript module (ESM) format is the official TC39 standard for packaging ... Before now, gatsby-config and gatsby-node had to be written in...
Read more >JavaScript Import vs Require Statements in Gatsby, Next.js ...
Why there is a difference of usage between the import statement and the require statement in different parts of the project directories ...
Read more >Gatsby config with TypeScript - miyauci.me
It mentions the different execution environments and module systems for each Config ... As for features, gatsby-config and gatsby-node assume CommonJS .
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Okay, I’ll take a shot at it.
From what I can tell. Here are the changes that need to take place:
packages/Gatsby/src/internal-plugins/internal-data-bridge/gatsby-node
, add the require highjack:…Along with––at line 121––swapping out the
require
withinteropRequire
One question: where are the other user-defined config resources being required? I searched for a while but couldn’t find exactly where it happens. If anyone could let me know, that would be so so nice. Thanks 💯
@wardpeet I like that solution––esm is a great project. Could you or someone who has familiarity with the Gatsby codebase speak to whether the current caching would play nice with esm’s? If so, supporting ESModules would be as easy as adding the require highjack. Would love to be able to use this syntax.