Skip to content

Edge function bundling fails if code is loaded from private source (DENO_AUTH_TOKENS) #959

Closed

Description

@evelant

Bug report

  • [X ] I confirm this is a bug with Supabase, not with my own application.
  • [ X] I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Loading dependencies from a private source fails when bundling edge functions. I've got an auth token for the private code in env.DENO_AUTH_TOKENS (per deno docs) and Deno can download and cache the code without issue. The function runs fine locally but bunding fails as soon as I attempt to deploy.

error: Uncaught (in promise) Error: Module not found "https://raw.githubusercontent.com/path/to/my/private/code/privateModule.ts".
      const ret = new Error(getStringFromWasm0(arg0, arg1));
                  ^
    at __wbg_new_8d2af00bc1e329ee (https://deno.land/x/[email protected]/eszip_wasm.generated.js:312:19)
    at <anonymous> (https://deno.land/x/[email protected]/eszip_wasm_bg.wasm:1:79439)
    at <anonymous> (https://deno.land/x/[email protected]/eszip_wasm_bg.wasm:1:1388039)
    at <anonymous> (https://deno.land/x/[email protected]/eszip_wasm_bg.wasm:1:1862894)
    at __wbg_adapter_18 (https://deno.land/x/[email protected]/eszip_wasm.generated.js:146:6)
    at real (https://deno.land/x/[email protected]/eszip_wasm.generated.js:130:14)

To Reproduce

  1. Create a new edge function
  2. Add a dependency to the edge function that requires DENO_AUTH_TOKENS to access (such as a private github repo)
  3. Verify that DENO_AUTH_TOKENS is correct then observe that deno cache -r index.ts caches the files without problem. Also observe that supabase functions serve my-function works without issue.
  4. Run supabase functions deploy my-function and observe the crash during bundling when it cannot access the files in the private repository

Expected behavior

Anything that works locally should successfully bundle and deploy.

Screenshots

N/A

System information

  • OS: macOS
  • Browser (if applies) [e.g. chrome, safari]
  • Version of supabase-js: 1.45.2
  • Version of Node.js: 16.19.0

Additional context

This is blocking me from progressing in my migration from firebase to supabase. Everything works locally but I can't deploy due to this bug.

Activity

  1. added
    bug
    on Mar 25, 2023
  2. evelant commented on Mar 25, 2023

    @evelant
    Author

    This appears to be an issue with eszip denoland/eszip#121

    Another problem here is that when the bundling process fails it does not give any useful debug output. I think this is due to the code here https://github.com/supabase/cli/blob/main/internal/utils/denos/build.ts where it just throws a useless error such as "file not found" without logging what file it was trying to read.

    I also can't find https://github.com/supabase/cli/blob/main/internal/utils/denos/build.ts anywhere in my node_modules, is it compiled directly into the supabase binary? I wanted to patch it to get more useful output but am unable to find it.

  3. laktek commented on Mar 25, 2023

    @laktek
    Contributor

    @evelant Will take a look at this issue next week.

    I also can't find https://github.com/supabase/cli/blob/main/internal/utils/denos/build.ts anywhere in my node_modules, is it compiled directly into the supabase binary? I wanted to patch it to get more useful output but am unable to find it.

    You can clone the Supabase CLI repo and run it with a patched version of the file locally. Instructions on how to run it locally should be available in the repo.

  4. soedirgo commented on Mar 30, 2023

    @soedirgo
    Member

    Just a note for the fix

    • for functions deploy, you need to run it like: DENO_AUTH_TOKENS=... supabase functions deploy foo
    • for functions serve, you need to set DENO_AUTH_TOKENS inside your --env-file

    Let us know if that works!

  5. evelant commented on Apr 4, 2023

    @evelant
    Author

    @soedirgo @laktek it works now, thank you!

  6. added this to the P1 milestone on Jul 3, 2024
  7. sweatybridge commented on Oct 30, 2024

    @sweatybridge
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions