Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deno / Deno Deploy compatibility #161

Closed
jcs224 opened this issue Apr 18, 2021 · 26 comments
Closed

Deno / Deno Deploy compatibility #161

jcs224 opened this issue Apr 18, 2021 · 26 comments
Assignees
Labels
enhancement New feature or request
Projects

Comments

@jcs224
Copy link

jcs224 commented Apr 18, 2021

Feature request

Is your feature request related to a problem? Please describe.

I tried importing a Skypack and jspm version of the supabase-js client library, without success. I can create issues for the problems if you want, but since no one has brought up Deno yet I thought I'd start with a feature request.

Also, it would be really cool to be able to use Supabase with the new Deno Deploy service, just announced a couple of weeks ago.

https://deno.com/deploy

Describe the solution you'd like

Compatibility and instructions on how to use Deno / Deno Deploy with Supabase.

Describe alternatives you've considered

Using Node, of course :p but Deno is really nice to use and seems ambitious and forward thinking, similar to Supabase.

Additional context

Add any other context or screenshots about the feature request here.

@jcs224 jcs224 added the enhancement New feature or request label Apr 18, 2021
@kiwicopple kiwicopple added this to Triage in Tools via automation Apr 19, 2021
@kiwicopple
Copy link
Member

it would be really cool to be able to use Supabase with the new Deno Deploy service

Nice one, thanks @jcs224. Did you attempt this one already? Where there any issues/errors?

@jcs224
Copy link
Author

jcs224 commented Apr 19, 2021

@kiwicopple I didn't try it with Deno Deploy yet, just the regular Deno CLI. I will try it with Deno Deploy, I'm sure the issues will be similar. Deno Deploy only has a subset of the Deno CLI since it's meant to run in an idempotent serverless environment (at least that's my understanding).

The first show-stopper has to to with XMLHttpRequest, which isn't present in Deno, and seems like this would be addressed if #154 is fixed.

Once I tried a workaround to ignore the XMLHttpRequest keyword, I got an error from GoTrue saying that getItem is not defined, probably referring to localStorage which Deno also doesn't support. It looks like it's on Deno's roadmap, but it's not implemented yet.

@jcs224
Copy link
Author

jcs224 commented Apr 19, 2021

As I look into it more, I might try just using the postgrest-js library instead of the whole Supabase client. The current supabase-js implementation seems more focused on the browser environment than the server one, understandably. Although Deno has quite a bit of browser-compatible APIs, it's not all quite there (and may never be?)

@kiwicopple
Copy link
Member

Agreed 👍 . This will still be compatible with Supabase projects too (you can just append /rest/v1 to the URL). Thanks for looking into this @jcs224

@jcs224
Copy link
Author

jcs224 commented Apr 19, 2021

So, just tried this with postgrest-js and ran into the same XMLHttpRequest issue as before, because of the cross-fetch dependency. Maybe I'll fork that dependency and see if I can finagle it into submission.

@kiwicopple
Copy link
Member

If you manage to solve it in cross-fetch, you'd also solve the problem for Cloudflare workers and Vite, so that would be a huge contribution

@jcs224
Copy link
Author

jcs224 commented Apr 19, 2021

A little bit of a shot in the dark (hard to test with Deno as Skypack and jspm aren't cooperating with my test packages), but I sent a PR to cross-fetch's dependency, whatwg-fetch, to see what happens.

@abnemo
Copy link

abnemo commented Apr 27, 2021

A little bit of a shot in the dark (hard to test with Deno as Skypack and jspm aren't cooperating with my test packages), but I sent a PR to cross-fetch's dependency, whatwg-fetch, to see what happens.

Hello =) Any news on PR? I'd really like to use supabase-js client in deno environment, but because of lack of XMLHttpRequest, it is not possible =(

@jcs224
Copy link
Author

jcs224 commented Apr 30, 2021

@abnemo this is an upstream dependency that will likely need to be updated. You should add a comment or give an emoji on this issue, maybe it will help get the ball rolling: JakeChampion/fetch#956

@salemalem
Copy link

I would love to see a dedicated supabase package on Deno land.

@mirus-ua
Copy link

mirus-ua commented Jun 1, 2021

Tried to run supabase-js today via cdn.skypack.dev and still got XMLHttpRequest error at cross-fetch

@jcs224
Copy link
Author

jcs224 commented Jul 25, 2021

Well, someone ported all the Supabase JS libraries to Deno!

I tried just running Skypack, esm.sh, and jspm versions of Supabase, still not working. But, maybe stuff from these ports can be merged in with Supabase proper somehow? @link-discord?

@jcs224
Copy link
Author

jcs224 commented Jul 25, 2021

@salemalem ☝️

@link-discord
Copy link

link-discord commented Jul 25, 2021

yeah I was crazy enough to go ahead and port everything.
wasn't really that hard cuz the supabase packages itself only ever use 1 dependency

@link-discord
Copy link

What also helped porting is the fact they added websocket support to deno while I was porting the realtime lib

@link-discord
Copy link

Also none of the ports use external dependencies only native things built in deno just so you know

@littledivy
Copy link

The following works with esm.sh:

import "https://deno.land/x/xhr@0.1.2/mod.ts";
import { createClient } from "https://esm.sh/@supabase/supabase-js";

const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key');
console.log(supabase.supabaseUrl); // https://xyzcompany.subabase.co

@andrew-pyle
Copy link

andrew-pyle commented Oct 20, 2021

While the Deno runtime does support LocalStorage, and the supabase-js package works there, the code will not run on the Deno Deploy service.

Deno Deploy doesn't support LocalStorage, even though the Deno runtime does. The linked proposal indicates thatLocalStorage won't ever be implemented, since it's synchronous.

That means the Deno port of supabase-js (https://deno.land/x/supabase@1.2.0/) doesn't work on Deno Deploy.

Anyone tried the Deno port of PostgREST (https://deno.land/x/postgrest) with Deno Deploy specifically?

@salemalem
Copy link

@andrew-pyle
so we won't see Supabase + Deno combination? What's at least Supabase analog in Deno?

@andrew-pyle
Copy link

@salemalem My observations above are specifically about the Deno Deploy service.

The Deno port of supabase-js works fine with Deno on the command line.

@salemalem
Copy link

@salemalem My observations above are specifically about the Deno Deploy service.

The Deno port of supabase-js works fine with Deno on the command line.

Oh so it will work perfectly if I will host it on Digital Ocean, right?

@andrew-pyle
Copy link

Give it a try and let us know what happens. It should work as far as I can tell.

@link-discord
Copy link

I haven't updated the ports in a while but I will probably update them soon again

@link-discord
Copy link

I just updated all the deno ports to match the current code of the supabase js libs

@soedirgo
Copy link
Member

The official recommendation is to use supabase-js via esm.sh (it wasn't working at the time this issue was created, but should work now).

The situation with LocalStorage on Deno is unfortunate (there's a similar issue on Node) - you might need to use the service_role key which bypasses RLS (make sure to harden your Function!) instead of signing in with Auth.

@ije
Copy link

ije commented Mar 23, 2023

esm.sh v112 will inject XHR polyfill for cross-fetch automatically now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Tools
Triage
Development

No branches or pull requests

10 participants