-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gatsby-config/node.js doesn't support ESM import/export #23705
Comments
It's worth highlighting the following parts of the release docs:
So I expect there's still some time before this will be implemented. |
Fair enough. Although it's probably a good idea to start looking into this now.
|
Thank you for opening this! As they say:
So I don't think this is ready yet for prime-time in Gatsby as we can ship more impactful features than trying to keep up with breaking changes from them. We want to support it of course once it reached a stable status. We're marking this issue as answered and closing it for now but please feel free to comment here if you would like to continue this discussion. We also recommend heading over to our communities if you have questions that are not bug reports or feature requests. We hope we managed to help and thank you for using Gatsby! |
@thecodingaviator did you try it actually? Because I think you should be able to import ESM into CJS. You would require it from gatsby-node.js to run it on a certain Gatsby API. |
For xdm specifically, I've tried a variety of techniques to import it into Gatsby (including using the |
I'm facing a similar issue as @thecodingwizard where I want to use the latest |
@LekoArts @KyleAMathews Node 16 is out, this is no longer experimental and should be reopened. |
Same problem here. Several gatsby-remark plugins are created inside the
Let us know if we need to open a new issue. |
Please open a feature request for ESM support here: https://github.com/gatsbyjs/gatsby/discussions/categories/ideas-feature-requests |
hi @kimbaudi have you found a solution for this? We're facing similar issues |
@Ir1d - I haven't found a solution to using import/export in gatsby-config/node.js. The closest I got to using import/export in gatsby-config/node.js is by using the // site.js
const site = {
title: `my title`,
description: `my description`,
url: `https://example.com`,
};
export default site; and I use // esm.js
require = require('esm')(module)
const {default: site} = require('./site')
module.exports = {
site
} this way, I can use const {site} = require('./src/config/esm')
module.exports = {
siteMetadata: site,
...
} However, this no longer works if you try to convert .js/jsx to .ts/tsx files. I know you can convert .jsx files to .tsx in Gatsby, but |
We tried using esm's require, but it isn't of much success |
@tujoworker I'm aware of the plugin, but haven't used it myself. @Ir1d esm require only works if the es module you are requiring is serializable. If esm's require doesn't work for you, it probably means you are requiring non-serializable js such as react components or something else I'm unaware of. |
yeah, that probably won't work since |
indeed. afaik, no one has ever been able to make gatsby work with esm module unist-util-visit |
One thing that I imagine would work would be to compile the But setting that up... 😬 |
It requires complex configuration and I don't think that's what remark wanted when they decided to upgrade to esm.. |
Not «that» complex, see the this doc: https://support.gatsbyjs.com/hc/en-us/articles/1500000294121-Using-ES6-Module-Syntax-in-Gatsby-API-Files-on-Gatsby-Cloud Sure, I agree, having that build in, would be very nice! |
This doesn't work - just tried it with the new pure ESM packages (for example, Also, this was not my suggestion. |
This isn't a "nice to have" or "has a workaround" - Gatsby just doesn't work with new versions of many packages. |
@tujoworker thx, but that method doesnt work with remark ecosystem. i've tried that before. |
Okay! There is at least some activity going on: https://twitter.com/wardpeet/status/1422843507283316736?s=21 |
Nope, dynamic import using
Without the top-level await, it would need to have some way of accessing the value in the |
You can return an function as the configuration, inside |
Yeah probably doesn't work with promises. I don't even see anything in the docs about the option to return a function. |
Ah, the reason I can't find it in the docs is because returning a function in
And yeah, that doesn't support promises / async functions:
|
Has anyone found a way to make Gatsby work with pure ESM package like |
@bytrangle No known way currently. Gatsby is only compatible with packages that are NOT pure ESM. Downgrade to older versions for use with Gatsby. The Gatsby team is apparently "not against" moving to ESM (tweet from @wardpeet), but I'm guessing it will still be some time before you can use this in your projects. If you absolutely need to use the new versions now, you may want to try experimenting with bundling / precompiling the dependency to CommonJS, although this may be complex. |
Please follow & comment on #31599 - it's on our radar but for now we have other things that are higher priority for us + we can't directly act on it without prior planning. |
Ok, will do, maybe can you lock this thread then? |
Please go to #34613 and you can use TypeScript with Gatsby. By the time you're reading this it's also possible that the feature already was shipped in Gatsby 4. If that is the case the RFC will be marked as done. You can also expect ESM support (through this) very soon, please follow #31599 for progress. Again, if the feature is shipped it'll be noted in the discussion. |
Summary
Node v14 is out and with it the removal of the Experimental Modules warning! 🎉
I installed it, added
"type": "module"
topackage.json
, usedexport default
ingatsby-config.js
and took the default starter for a spin. This is what I got: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
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:
If that doesn't get you excited, you must be in the wrong line of work. 😄
The text was updated successfully, but these errors were encountered: