Can't deploy Nuxt app on workers.

my app gets all the way to the "11:30:35.029 ✨ Upload complete! 11:30:37.956 Success: Assets published! 11:30:40.343 Error: Failed to publish your Function. Got error: Uncaught Error: supabaseUrl is required. at chunks/runtime.mjs:1:1400415 in Vw.default at chunks/runtime.mjs:1:1404632 in e.createClient at chunks/runtime.mjs:1:1404766" stage, then gives this error... All my environment variables are set up properly, everything works fine on digitalocean app platform, just not cloudlfare workers. Could my problem be the script size limit?
32 Replies
Chaika
Chaika5mo ago
#pages-help If it was size limit it'd say so. Worth noting I believe DigitalOcean is a node environment, but Workers is V8/Web-like JS Environment. It looks like it just can't resolve the supabaseUrl in your Function, there's lots of hits for that on google: https://www.google.com/search?client=firefox-b-1-d&q=Got+error%3A+Uncaught+Error%3A+supabaseUrl+is+required.
0xSherlock
0xSherlockOP5mo ago
nothing really explains the issue though, supabaseUrl is defined, i have it in my .env variables, infact i can see it when i console log it
Chaika
Chaika5mo ago
your function isn't going to pick up your .env file (in production/deployed)
0xSherlock
0xSherlockOP5mo ago
oh i see, what do you recommend to help pick it up?
Chaika
Chaika5mo ago
If supabase even works with Workers, you'd likely want to set it under the Pages -> Settings -> Environment Variables section
0xSherlock
0xSherlockOP5mo ago
i do have the environment variables setup in cloudflare settings as well so its still not working that way
Chaika
Chaika5mo ago
Cloudflare Docs
Supabase · Cloudflare Workers docs
Supabase is an open source Firebase alternative and a PostgreSQL database service that offers real-time functionality, database backups, and …
Chaika
Chaika5mo ago
how are you using supabase? are you using @supabase/supabase-js and passing the ENV to it, like in that?
0xSherlock
0xSherlockOP5mo ago
im using js package
0xSherlock
0xSherlockOP5mo ago
No description
0xSherlock
0xSherlockOP5mo ago
like this
0xSherlock
0xSherlockOP5mo ago
No description
0xSherlock
0xSherlockOP5mo ago
No description
0xSherlock
0xSherlockOP5mo ago
perhaps i need to use env instead of process.env?
Chaika
Chaika5mo ago
With the request context yea. Workers are V8 Isolates/not node, so process.env either doesn't exist, or with nodejs compat enabled, it exists but is empty
0xSherlock
0xSherlockOP5mo ago
No description
0xSherlock
0xSherlockOP5mo ago
should i just give this a try then? lol
Chaika
Chaika5mo ago
you'd have to get the request context the way of doing that depends on your framework it looks like you might be creating that outside of the request lifecycle/in a global way? If so, that's a bad idea with Workers, should all be scoped to each request
0xSherlock
0xSherlockOP5mo ago
this is my api code in nuxt, so it runs on its own outside of requests but if workers doesn't use node, maybe it doesnt run at all. Most of all my server side code is supposed to run indefinitely on its own in node
Chaika
Chaika5mo ago
it'll run, but it just won't work you don't have the env outside of the request, and even if you did/you hardcoded it, Workers will throw up at you after the first request, as each promise/awaited task should be created within a request's life cycle
Most of all my server side code is supposed to run indefinitely on its own in node
You have background actions or something?
0xSherlock
0xSherlockOP5mo ago
yeah exactly i have websockets running in the background and processing the data continuously
Chaika
Chaika5mo ago
you'd have to rework them. Workers are spun up and created dynamically on the edge, with no affinity or anything. You could get 1000 requests and if none hit the same machine/metal, you'd have 1,000 running workers Additionally the way the runtime tracks async promises, is such that if you do work outside of a request and try to await it within a request, it will error out "Request hasn't returned but this request has no more tracked i/o", kind of thing. Everything should be scoped to the request's life span
0xSherlock
0xSherlockOP5mo ago
damn, so maybe workers isnt for me
Chaika
Chaika5mo ago
If you wanted to do some sort of fanning out/listening to a websocket and replicating it out, you could consider Durable Objects. They're like Workers in the sense they're a single Isolate running, but globally consistent and without as many of the per request restrictions. You could keep a ton of websockets open to a Durable Object and have it spit out messages to them as needed
0xSherlock
0xSherlockOP5mo ago
im just trying to find something simple that will run like digital oceans app platform, as thats what my infrastructure is based on rn all my data processing, websockets, 10+ server side code, all runs independtently on a consistent nitro server i thought workers could be good alternative to DO app platform, but seems i would need to rework all my code basically i would really love to be able to use cloudflare but it seems quite complex to rework my entire server side code to get it working the same way it was with a node environment
Chaika
Chaika5mo ago
Yea, they just aren't node. They scale to the moon because of their tight restrictions (startup usually instantly, but has to be less then 500ms, so they can spin up thousands easily), they run on the same CF Metal that received the request, not a lb inbetween or anything
0xSherlock
0xSherlockOP5mo ago
yeah, startup isnt too concerning for me, mine takes a long time regardless i think cause of the huge infrastructure is there any node-type alternatives you know of? digitalocean works great for me on the app platform, but they dont offer much flexibility for vcpu/ram choices
Chaika
Chaika5mo ago
none that I really know of/like other then fly.io which is way more generic/any container app
0xSherlock
0xSherlockOP5mo ago
ok, ill check that out lol im experiencing same error with fly
0xSherlock
0xSherlockOP5mo ago
No description
0xSherlock
0xSherlockOP5mo ago
No description
0xSherlock
0xSherlockOP5mo ago
ive defined the environment variables and everything, im so confuuuuused Okay I've discovered that the problem is the code is running during build time in the environment variables aren't available until after build
Want results from more Discord servers?
Add your server