supabase icon indicating copy to clipboard operation
supabase copied to clipboard

Vercel Edge, Cloudflare Workers, ReferenceError: global is not defined

Open MarianMichalovic opened this issue 2 years ago • 4 comments
trafficstars

Version

@nuxtjs/supabase: 0.3.0 nuxt: 3.0.0

Cloudflare Workers:

  • wrangler deploy failed ReferenceError: global is not defined

Vercel Edge

  • after deploy ReferenceError: global is not defined

In project only @nuxtjs/supabase package. Without @nuxtjs/supabase with supabase-js works correct.

MarianMichalovic avatar Nov 29 '22 03:11 MarianMichalovic

Running into this, too. Here's a repo to reproduce this: https://github.com/kevcodez/nuxt-on-the-edge

Fork and deploy that to Vercel and open the page.

ReferenceError: global is not defined
    at worker.js:21:39244
    at worker.js:14:173
    at fn (worker.js:53:15532)
    at Object.<anonymous> (worker.js:57:5)
    at Object.<anonymous> (worker.js:59:6)
    at De (worker.js:77:13740)
    at worker.js:77:15871

kevcodez avatar Dec 03 '22 11:12 kevcodez

Cloudflare workers require node_compat = true in wrangler.toml https://developers.cloudflare.com/workers/wrangler/configuration/#node-compatibility

image

With this setup it works.

MarianMichalovic avatar Dec 19 '22 11:12 MarianMichalovic

Same here : https://github.com/nuxt-modules/supabase/issues/158

Zebnastien avatar Feb 25 '23 17:02 Zebnastien

I've encountered the same problem on cloudflare after migrating from yarn to pnpm (deployment failed ... even with 0 code). Turns out, it's caused by the way pnpm is isolating packages - which is why it's working fine on yarn, but not with pnpm.

adding public-hoist-pattern[]=@supabase/supabase-js* to .npmrc does seem to fix this for me on cloudflare workers - at least with "@nuxtjs/supabase": "^1.2.0" (no other workarounds applied).

if i'll still encounter problems down the road, i'm not sure - but for me, i got the "global is not defined" error already on deployment, at the "Deploying to Cloudflare's global network" step.

xmatthias avatar Apr 15 '24 16:04 xmatthias