sveltejs / kit

web development, streamlined
https://svelte.dev/docs/kit
MIT License
18.65k stars 1.92k forks source link

Dynamic import not supported with netlify edge function #12057

Open mig-hub opened 7 months ago

mig-hub commented 7 months ago

Describe the bug

I have Mailchimp signup that is implemented using the @mailchimp/mailchimp_marketing api client on a form action. It work perfectly on my dev environment. But when I deploy it on Netlify with the netlify adapter and edge: true, then the form does not work in production. In the edge function logs, this is what I have:

Error: Dynamic require of "node:querystring" is not supported

The import happens in this file:

@mailchimp/mailchimp_marketing/src/ApiClient.js

I don't really know if the problem is with the adapter, the mailchimp client, or netlify edge functions themselves.

Does anybody know what is the best way to investigate this and if there is a fix/workaround I can apply at my end, or if one of the libraries involved needs to be fixed?

Reproduction

As far as I can tell, any project using the netlify adapter with edge: true and having a form action that directly or indirectly tries to import "node:querystring" (@mailchimp/mailchimp_marketing in this case) would throw this error.

Logs

Mar 29, 02:43:56 PM: 01HT577V error  Error: Dynamic require of "node:querystring" is not supported
Mar 29, 02:43:56 PM: 01HT577V error      at file:///root/.netlify/edge-functions/render.js:13:9
Mar 29, 02:43:56 PM: 01HT577V error      at node_modules/@mailchimp/mailchimp_marketing/src/ApiClient.js (file:///root/.netlify/edge-functions/render.js:22428:23)
Mar 29, 02:43:56 PM: 01HT577V error      at __require2 (file:///root/.netlify/edge-functions/render.js:19:50)
Mar 29, 02:43:56 PM: 01HT577V error      at node_modules/@mailchimp/mailchimp_marketing/src/index.js (file:///root/.netlify/edge-functions/render.js:22780:21)
Mar 29, 02:43:56 PM: 01HT577V error      at __require2 (file:///root/.netlify/edge-functions/render.js:19:50)
Mar 29, 02:43:56 PM: 01HT577V error      at .svelte-kit/output/server/entries/pages/bid/contact/_page.server.js (file:///root/.netlify/edge-functions/render.js:22801:42)
Mar 29, 02:43:56 PM: 01HT577V error      at __init (file:///root/.netlify/edge-functions/render.js:16:56)
Mar 29, 02:43:56 PM: 01HT577V error      at .svelte-kit/output/server/nodes/5.js (file:///root/.netlify/edge-functions/render.js:22900:5)
Mar 29, 02:43:56 PM: 01HT577V error      at __init (file:///root/.netlify/edge-functions/render.js:16:56)Mar 29, 02:43:56 PM: 01HT577V error      at file:///root/.netlify/edge-functions/render.js:27903:52

System Info

System:
    OS: macOS 12.6.9
    CPU: (8) arm64 Apple M1
    Memory: 72.97 MB / 8.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.18.0 - ~/.nvm/versions/node/v18.18.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.8.1 - ~/.nvm/versions/node/v18.18.0/bin/npm
  Browsers:
    Chrome: 123.0.6312.87
    Safari: 16.6
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.1.0
    @sveltejs/adapter-netlify: ^4.1.0 => 4.1.0
    @sveltejs/kit: ^1.20.4 => 1.30.4
    svelte: ^4.0.5 => 4.2.1
    vite: ^4.4.2 => 4.5.2

Severity

annoyance

Additional Information

Not sure it makes a difference but the node version at Netlify's end is 18.20.0.

filipwiniarski commented 3 months ago

Having the same issue but with the mixpanel package!

filipwiniarski commented 3 months ago

I've created a thread on Netlify's community forum as well: https://answers.netlify.com/t/dynamic-require-of-node-querystring-is-not-supported/121848