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

UnsupportedError occurs when using the HTTP package on the Supabase platform #34

Open
htsuruo opened this issue May 3, 2023 · 5 comments

Comments

@htsuruo
Copy link

htsuruo commented May 3, 2023

I am running on Supabase Edge.

As far as I understand from Fetching Data, it is possible to fetch data using two approaches, Fetch and HTTP Package.

However, the sample does not describe how to use it with platforms such as Supabase or Vercel using http.runWithClient.

When I tried writing the following code, an UnsupportedError occurred:

UnsupportedError {
  message: "Cannot create a client without dart:html or dart:io.",
  "$thrownJsError": Unsupported operation: Cannot create a client without dart:html or dart:io.
    at Object.wrapException (file:///home/deno/functions/dart_edge/main.dart.js:1051:17)
    at Object.throwExpression (file:///home/deno/functions/dart_edge/main.dart.js:1065:15)
    at Object.createClient (file:///home/deno/functions/dart_edge/main.dart.js:11473:16)
    at file:///home/deno/functions/dart_edge/main.dart.js:7067:44
    at _wrapJsFunctionForAsync_closure.$protected (file:///home/deno/functions/dart_edge/main.dart.js:3609:15)
    at _wrapJsFunctionForAsync_closure.call$2 (file:///home/deno/functions/dart_edge/main.dart.js:14042:12)
    at Object._asyncStartSync (file:///home/deno/functions/dart_edge/main.dart.js:3573:20)
    at Object._withClient$body (file:///home/deno/functions/dart_edge/main.dart.js:7103:16)
    at Object._withClient (file:///home/deno/functions/dart_edge/main.dart.js:7050:16)
    at Object.get (file:///home/deno/functions/dart_edge/main.dart.js:7047:16)
}
Reproducible code

void main() {
  http.runWithClient(() async {
    SupabaseFunctions(fetch: (request) async {
      // Get IP address
      final response = await http.get(
        Uri.parse('http://httpbin.org/ip'),
        headers: {'Content-Type': 'application/json'},
      );
      if (response.statusCode == 200) {
        final json = response.body as Map<String, dynamic>?;
        print(json);
        return Response.json(json);
      }
      return Response.error();
    });
  }, () => EdgeHttpClient());
}

Is my usage incorrect? Or is the HTTP package not yet supported in Supabase?
It was available with the Fetch API.


I want to use packages like dart_openai | Dart Package, but since their internal implementation depends on http, I cannot use them without resolving the above issue.

Thanks.

@htsuruo htsuruo changed the title UnsupportedError occurs when using the HTTP package on the Supabase platform. UnsupportedError occurs when using the HTTP package on the Supabase platform May 3, 2023
@MichealReed
Copy link

MichealReed commented May 3, 2023

Closed my related issue and wanted to add @htsuruo's very cool example repository. May be very useful in diagnosing this -- https://github.com/HTsuruo/dart-edge-supabase-playground/tree/main

Thanks for the guide and workaround too 🙏

@MichealReed
Copy link

Maybe an override of dart:html with https://pub.dev/packages/universal_html would work?

@Zekfad
Copy link

Zekfad commented May 17, 2023

If fetch is conforms to browsers' one you may try to use fetch_client, it is independent of io or html, using only js interop to call global fetch function.

@noga-dev
Copy link

Maybe an override of dart:html with https://pub.dev/packages/universal_html would work?

Tried.

root@DESKTOP-IAH5ULT:/mnt/d/src/hackathons/2023/intellitask/functions# npx supabase functions serve dart_edge --no-verify-jwt --env-file ./.env
Serving functions with legacy supabase/deno-relay:v1.6.0... Run functions serve instead to use Edge Runtime.
Starting supabase/functions/dart_edge
Serving supabase/functions/dart_edge
Watcher Process started.
Check file:///home/deno/functions/dart_edge/index.ts
UnsupportedError {
  message: "Platform._version",
  "$thrownJsError": Unsupported operation: Platform._version
    at Object.wrapException (file:///home/deno/functions/dart_edge/main.dart.js:2247:17)
    at Object._Platform__version (file:///home/deno/functions/dart_edge/main.dart.js:8509:15)
    at Object._Platform_version (file:///home/deno/functions/dart_edge/main.dart.js:8565:16)
    at file:///home/deno/functions/dart_edge/main.dart.js:39067:74
    at Object.holder.<computed> [as $get$Platform__version] (file:///home/deno/functions/dart_edge/main.dart.js:130:21)
    at Object.HttpClient_HttpClient (file:///home/deno/functions/dart_edge/main.dart.js:250:14)
    at WindowController_onChooseHttpClient_closure.call$1 (file:///home/deno/functions/dart_edge/main.dart.js:36649:75)
    at WindowController.onChooseHttpClient$1 (file:///home/deno/functions/dart_edge/main.dart.js:36642:44)       
    at file:///home/deno/functions/dart_edge/main.dart.js:36609:48
    at _wrapJsFunctionForAsync_closure.$protected (file:///home/deno/functions/dart_edge/main.dart.js:4927:15)

@noga-dev
Copy link

Sounds like the only way to get OpenAI's API to work atm is to call another function which handles the call and just returns the result.

https://supabase.com/docs/reference/javascript/functions-invoke

Which defeats the point of using Dart Edge functions at all, and one may as well just use Deno to begin with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants