#problem Node.js API not working in vercel

70 messages · Page 1 of 1 (latest)

pine oyster
#

Hello,
I'm posting a message here because I encountered a problem when trying to update [email protected]. When I deploy on vercel I get this error:
RollupError: Cannot bundle Node.js built-in "stream" imported from "node_modules/.pnpm/@[email protected]/node_modules/@supabase/node-fetch/lib/index.js". Consider disabling ssr.noExternal or remove the built-in dependency.

Apparently, @supabase/supabase-jsQwikCity does not support the built-in Node.js API.
Could someone please solve this problem?

north quartz
# pine oyster Hello, I'm posting a message here because I encountered a problem when trying to...

Hi I have run into the same kind of issue when using Cloudflare Pages.

The simple reason I found out is that to use Node.js, you need to start it up as a webserver, which is a no-no with edge providers.

It's called "serverless" for a reason, remember? That's what I realized myself. So it seems that you need to instead either:

  1. Use an alternative that does not rely on node.js APIs that are not supported by the adapter you are using, or
  2. Stop using a hosting service and instead use another one that possibly supports this, or buy a server that you then manage yourself. Then you can setup a qwik + node.js app with docker as an example
#

For example, I tried using nodemailer - but that does not work when using a serverless option because they do not support that kind of node.js functionality.

Some functionality can be polyfilled, however, but not everything. It may also depend on what provider you are using, I'm not entirely sure because I have not tried.

Instead, I had to go with a standard http request to an API endpoint for emailjs and use that instead to send my mails from a form.

#

And this isn't just specific to Qwik btw, this is just a general thing with serverless options

pine oyster
north quartz
pine oyster
north quartz
#

That's odd

#

So 1.2.11 worked for you but now it doesn't? Might be worth possibly opening an issue for if it's a qwik related thing.

violet kelp
#

@pine oyster can you go up in releases one by one to find which one breaks? Make sure you ONLY upgrade qwik+qwik-city.

pine oyster
pine oyster
north quartz
#

I'm just curious what it looks like

#

(and of course, hide anything that is sensitive info before sending here)

pine oyster
# north quartz Have you triaged what exact line(s) of code that depend upon supabase+node-fetch...

You can see this in the example I've added for the creation of the exit. From the moment I use the lib, I've just added a routeLoader to retrieve the session if it exists. So when I do a pnpm build it crashes.
https://github.com/BuilderIO/qwik/issues/5406

GitHub

Which component is affected? Qwik Runtime Describe the bug I'm trying to deploy my project locally on the Vercel preview using the Vercel Edge adapter. With the @supabase dependency to manage t...

pine oyster
#

@violet kelp Could you see where it was coming from?

violet kelp
frank pier
#

but I removed it from the cf adapter only

#

does vercel use the same adapter?

violet kelp
#

Maybe? Or perhaps @pine oyster misconfigured something?

frank pier
#

@pine oyster do you have a minimal repro I could test with?

#

I just saw there's a repro in the github issue, will use that

pine oyster
#

Thank you for your help 🙂

frank pier
#

so I don't think it's related to my patch at all, since it fails on build, but I'm not entirely sure what the issue is

#

I'm looking into it though, curious now what change broke this

frank pier
#

@pine oyster try in your adapters/vercel-edge/vite.config.ts changing the plugin options to this: vercelEdgeAdapter({ target: 'webworker' })

#

it should work

#

that patch defaults the target to node, so it changed the expected behaviour of the vercel adapter

#

I'll send a PR fix

#

so it defaults properly to webworker, I think that was the intention of the patch anyway as it's what was documented

frank pier
#

basically faulty logic meant it was defaulting to the node build

#

@quaint ferry you might want to take a look at this thread, since it was your PR originally that changed the logic here, let me know if you think we should be doing anything differently

frank pier
pine oyster
#

🙏

frank pier
#

No worries, I was worried I might have broken it in the first place! 😅

pine oyster
quaint ferry
#

@frank pier sorry for the delay, I’m a bit phased out because I’m drafted to reserve days in the ongoing war

#

Stream not working: we might be able to fix that. Polyfilling is an option but maybe we can also provide that from the platform. We are still in the same “not node, yet not webworker” situation

#

But totally get the defensive approach of just polyfilling

#

As long as env vars work, that sounds great. You are a magician 🙇‍♂️

#

And sorry for breaking it in the first place

frank pier
#

hey, no worries, I used to work in Herzliya so have a lot of friends in the same situation as you, hope things are well!

#

it seems the issue here was more with the ssr library for supabase not working well with the node target build, my PR just fixed the logic (so that the webworker build is the default again, which makes everything work fine in this case)

north quartz
frank pier
#

Yep

pine oyster
north quartz
frank pier
#

Yeah that’s not really a qwik specific issue either, cloudflare does have a node compat mode though that you can use to enable more node APIs but it’s not perfect

north quartz
frank pier
#

so the qwik cloudflare adapter exposes the platform object which has the cloudflare bindings, so that can be used to interact with the cloudflare APIs

#

it all depends on where you run your code though, if you run through vite this won't work out of the box – you have to run locally with wrangler instead

north quartz
#

Yeah that's the part I'm really confused over

frank pier
#

I've actually been meaning to do some work on the cloudflare adapter since some things like that are not super obvious

north quartz
#

Because my mental model isn't coherent between where cloudflare code begins and where qwik code begins

#

It's not like with normal database/backend connections where it just is available everywhere so long as you import it into the file

frank pier
#

so if you forget about qwik for a second, what cloudflare does is it allows you to run code in its cloud and when you run it there, the request handlers expose your cloudflare bindings so they're available in code

#

if you run your code locally (whether it's in vite dev server or directly with node or whatever else) you won't have access to these bindings because they are only available within cloudflare's environment (when the code runs in the cloud)

#

it's not like a database connection etc because they completely abstract how this connection happens, so it's not like you have an API/database connection string/etc that you can reach from outside, the cloudflare environment is only reachable when your code runs in cloudflare

#

however, there is a library called miniflare that replicates the workers environment locally within node

#

in the latest releases of wrangler (the cloudflare CLI tool) they integrated miniflare with wrangler so you can run your code within it transparently

#

so TL;DR: if you want to run your code locally with qwik + cloudflare you have to first do a build npm run build and then run wrangler pages dev ./dist which will load your code within miniflare

I suggest if you want we can take this to its own thread, I'm not sure if people here are going to be getting notifications from this 😅

north quartz