invertase / dart_edge

Run Dart on the Edge - supporting Vercel & Cloudflare Workers (more coming soon).
https://docs.dartedge.dev
Apache License 2.0
322 stars 23 forks source link

Cannot use `SupabaseClient` without dart:html or dart:io in Supabase Edge functions #57

Closed maksym-tielnyi-solid closed 1 year ago

maksym-tielnyi-solid commented 1 year ago

Describe the bug The SupabaseClient constructor throws "Cannot create a client without dart:html or dart:io." error when used in Supabase Dart Edge functions with the supabase_functions package. An error message looks like the following:

[Error] ub {
  a: "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.J (file:///home/deno/functions/dart_edge/main.dart.js:246:3)
    at Object.v (file:///home/deno/functions/dart_edge/main.dart.js:253:14)
    at Object.wV (file:///home/deno/functions/dart_edge/main.dart.js:2861:15)
    at Object.e2 (file:///home/deno/functions/dart_edge/main.dart.js:2859:14)
    at Object.Xa (file:///home/deno/functions/dart_edge/main.dart.js:2685:3)
    at e.$1 (file:///home/deno/functions/dart_edge/main.dart.js:5492:8)
    at file:///home/deno/functions/dart_edge/main.dart.js:5516:19
    at Gs.a (file:///home/deno/functions/dart_edge/main.dart.js:1401:63)
    at Gs.$2 (file:///home/deno/functions/dart_edge/main.dart.js:3545:14)
    at Object.DI (file:///home/deno/functions/dart_edge/main.dart.js:1381:11)
}

To Reproduce main.dart:

import 'package:edge_http_client/edge_http_client.dart';
import 'package:supabase/supabase.dart';
import 'package:supabase_functions/supabase_functions.dart';

void main() {
  SupabaseFunctions(fetch: (request) {
    final supabaseUrl = Deno.env.get('SUPABASE_URL')!;
    final supabaseKey = Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!;

    // This SupabaseClient constructor throws an error:
    SupabaseClient(
      supabaseUrl,
      supabaseKey,
      httpClient: EdgeHttpClient(),
    );

    return Response('OK');
  });
}

pubspec.yaml:

name: supabase_flutter_test
description: A sample command-line application.
version: 1.0.0

environment:
  sdk: ^3.0.6

dependencies:
  edge_http_client: ^0.0.1+3
  supabase: 1.11.9
  supabase_functions: 0.0.2+4

dev_dependencies:
  lints: ^2.0.0

Steps to reproduce the behavior:

  1. Build and serve the Edge function.
  2. Call the dart_edge function using Postman/curl/etc.
  3. Observe an Internal Server Error response and an error message in the functions console.

Version: supabase_flutter_test 1.0.0 ├── supabase 1.11.9 │ ├── functions_client 1.3.2 │ ├── gotrue 1.12.4 │ ├── postgrest 1.5.1 │ ├── realtime_client 1.3.0 │ ├── storage_client 1.5.3 └── supabase_functions 0.0.2+4

Additional context flutter doctor output:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.5 22G74 darwin-arm64, locale en-UA)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
[✓] Chrome - develop for the web
[!] Android Studio (not installed)
[✓] IntelliJ IDEA Community Edition (version 2023.1.4)
[✓] VS Code (version 1.82.2)
[✓] Connected device (2 available)
[✓] Network resources

! Doctor found issues in 1 category.
maksym-tielnyi-solid commented 1 year ago

It seems that this issue was caused by the 1.3.0 version of the realtime_client package, overriding it to version 1.2.3 helped.

dependency_overrides:
  realtime_client: 1.2.3

Related issue: https://github.com/supabase/supabase-flutter/issues/666