Support ESM usage with Gatsby #31599
Replies: 22 comments 27 replies
-
Hi. @wdavidw have you found solution on this? We are facing similar situations |
Beta Was this translation helpful? Give feedback.
-
No I haven't found any solution. I have tried using |
Beta Was this translation helpful? Give feedback.
-
@LekoArts @wardpeet Excuse me, do you have any idea on this? Thanks. |
Beta Was this translation helpful? Give feedback.
-
No known way to do this 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. |
Beta Was this translation helpful? Give feedback.
-
Update: I got the update to
At that point, I could start the Gatsby dev server with the new pure ESM dependency versions. cc @Ir1d @kimbaudi @wardpeet @LekoArts Caveat: In my specific case, I needed to also patch one of the dependencies ( |
Beta Was this translation helpful? Give feedback.
-
I'm slowly but surely looking into a strategy to make this possible. I can't put a date on it but just wanted to share that we're looking into it. We will first start with some utils and then move to plugin support. |
Beta Was this translation helpful? Give feedback.
-
@wardpeet if you need feedbacks, I am finishing to migrate the csv package to esm. I spent some time figuring out the right architecture. Our stack is js + .d.ts files for the source, using package.exports to expose modules in both cjs and esm versions (we also have a browser version), Mocha.js + Should.js, with tests written in CoffeeScript and Typescript. |
Beta Was this translation helpful? Give feedback.
-
We are currently using a solution that compile ES module using esm then forcing node to require it by catching ERR_REQUIRE_ESM |
Beta Was this translation helpful? Give feedback.
-
I started getting this error all of a sudden, with a
My website is broken and there's no way for me to fix it, I tried to upgrade the deps but it got even worse since I get the ESM incompatibilities issue reported here. |
Beta Was this translation helpful? Give feedback.
-
@FezVrasta this may help you.
esmRequire.js put this file in the root folder (same place as package.json)
Then use it in gatsby-config.js like this
|
Beta Was this translation helpful? Give feedback.
-
I guess this is why I have not managed to run tests using https://playwright.dev/ and keep getting errors concerning .mjs, not being able to find modules, modules not being defined in ES module scope when trying to run tests and not being able to set "type": "module" in package.json. I spent a few hours trying to get it work. But am giving up. I would appreciate if someone could tell me if this could be because of this issue or if I am simply doing something wrong? |
Beta Was this translation helpful? Give feedback.
-
With the new TypeScript configs from Gatsby 4.9, it's possible to patch only a single Gatsby internal file with all of the ESM packages, much easier! |
Beta Was this translation helpful? Give feedback.
-
Is this on the roadmap yet? |
Beta Was this translation helpful? Give feedback.
-
We've started work on this, you can follow the milestone: https://github.com/gatsbyjs/gatsby/milestone/15 (no ETA!) We'll first make Once we have a version published you can try out you'll find all details in the umbrella discussion - you can then also post your feedback there. |
Beta Was this translation helpful? Give feedback.
-
Hi! A couple questions for everyone we'd like your feedback on:
|
Beta Was this translation helpful? Give feedback.
-
Please see #37069, we now have instructions on how you give |
Beta Was this translation helpful? Give feedback.
-
Does
|
Beta Was this translation helpful? Give feedback.
-
ERROR Error in "/root/smutt_hole/Gatsby_ellipsis_system/node_modules/gatsby-source-hubspot/gatsby-node.js": require() of ES Module Error: [ERR_REQUIRE_ESM]: require() of ES Module /root/smutt_hole/Gatsby_ellipsis_system/node_modules/gatsby-source-hubspot/no |
Beta Was this translation helpful? Give feedback.
-
I'm trying to set up ESM on my gatsby website but it fails with
I decided to try debugging it through a fresh gatsby instance, but it also failed there (with the same error). what I did
then, I:
What else needs to be done in order to successfully launch |
Beta Was this translation helpful? Give feedback.
-
Hi
could you help me?
Let me know the gatsby-cli version with Node 16.0.0
On Sun, Mar 5, 2023 at 9:17 PM Smutt Bond ***@***.***>
wrote:
… Hi
Could you contact me now via Discord or Telegram?
SmuttChain#9020
17722492462
I want know
Thanks
On Mon, Mar 6, 2023 at 2:52 AM Smutt Bond ***@***.***>
wrote:
> Thank you very much
> I want to meet u via Discord
> plz add friend
> SmuttChain#9020
>
> On Mon, Mar 6, 2023 at 1:24 AM Piotr Rusin ***@***.***>
> wrote:
>
>> @luckhole007 <https://github.com/luckhole007> (and everyone else with a
>> similar issue) I just managed to fix it, and as I suspected, it was
>> something really silly. In order to make it work, you shouldn't be adding
>> "type": "module" to package.json. It breaks everything.
>>
>> The only things that are needed:
>>
>> - rename gatsby-config.js -> gatsby-config.mjs
>> - adjust mjs file(s) so it supports ESM syntax (replace
>> module.exports into export default, etc)
>>
>> —
>> Reply to this email directly, view it on GitHub
>> <#31599 (reply in thread)>,
>> or unsubscribe
>> <https://github.com/notifications/unsubscribe-auth/AVPPG6BO3D66FZPKJJFWMYTW2S435ANCNFSM45S7BTIA>
>> .
>> You are receiving this because you were mentioned.Message ID:
>> ***@***.***>
>>
>
|
Beta Was this translation helpful? Give feedback.
-
Awesome, thanks!
…On Wed, Mar 8, 2023 at 11:48 AM Benedikt Rötsch ***@***.***> wrote:
Well, the error message clearly tells you the limitations:
You need to use a dynamic import OR switch your whole file to use the new
syntax. Renaming to .mjs should help :)
—
Reply to this email directly, view it on GitHub
<#31599 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AVPPG6HDNL7RBB2DP74CERLW3BBXJANCNFSM45S7BTIA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hi there, I have implemented some private Gatsby themes to simplify developing new projects. As of Gatsby v5.3 it is possible to use ESM syntax in
After some investigation I found that the So in case anyone else gets this error, here is a patch to fix it:
Best, |
Beta Was this translation helpful? Give feedback.
-
Problem
Parts of the Node.js ecosystem are moving their packages to ESM and importing/using them together with Gatsby currently doesn't work. Users should be able to use ESM-only packages.
Solution
Please visit ESM in Gatsby files to learn how to use ESM with Gatsby.
Beta Was this translation helpful? Give feedback.
All reactions