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

running supabase functions serve fails. running supabase functions serve <name> causes postgres connection to fail #115

Open
2 tasks done
oldbettie opened this issue Jun 14, 2023 · 11 comments
Labels
bug Something isn't working

Comments

@oldbettie
Copy link

oldbettie commented Jun 14, 2023

Bug report

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

Describe the bug

seems like there is an issue with a deno package when running supabase functions serve I get this following error.

worker "/home/deno/functions/scraper" returned an error: Uncaught SyntaxError: The requested module '/v125/jszip@3.5.0/esnext/lib/readable-stream-browser.js' does not provide an export named 'default'
    at https://esm.sh/v125/jszip@3.5.0/esnext/jszip.mjs:2:291
InvalidWorkerCreation: worker boot error
    at async Function.create (ext:sb_user_workers/user_workers.js:80:21)
    at async Server.<anonymous> (file:///home/deno/main/index.ts:95:24)
    at async Server.#respond (https://deno.land/std@0.182.0/http/server.ts:220:24)

if I run supabase functions serve <function-name> --env-file supabase/.env then it will work once but needs to be restarted after every run.

seems to only be when done locally. which makes it incrediby frustrating to have to deploy changes everytime we want to test a function.

To Reproduce

start supabase and run supabase functions serve

Expected behavior

the functions should work

A clear and concise description of what you expected to happen.
the function should execute and hot reload locally as expected. deno seems to be flawed

System information

  • OS: Ventura 13.4
  • Browser chrome
  • Version of supabase-js: 1.68.6
  • Version of Node.js: 20.3.0

Additional context

seems like local lambda is still quite buggy.

@oldbettie oldbettie added the bug Something isn't working label Jun 14, 2023
@gregnr
Copy link
Member

gregnr commented Jun 14, 2023

Thanks for reporting @oldbettie. That would definitely be frustrating having to deploy each time just to test - not at all the intended pattern.

I took a look into jszip and it looks like they are doing some advanced import logic with readable-stream (where you are getting the error).

@supabase/edge-functions it's not clear to me why this would work on Deno Deploy but not edge-runtime - any chance the import logic is slightly different between the two (eg. User-Agent sent to esm.sh to determine the build target)?

@oldbettie in the mean time I was able to solve this specific problem by adding ?bundle to the esm.sh import:

import JSZip from 'https://esm.sh/v125/jszip@3.5.0?bundle';

which tells esm.sh to bundle all dependencies into a single JS file.

Let me know if this helps.

@gregnr gregnr transferred this issue from supabase/supabase Jun 14, 2023
@laktek
Copy link
Contributor

laktek commented Jun 14, 2023

@gregnr Did the import work when function was deployed to Deno Deploy? Will try to reproduce it.

@oldbettie
Copy link
Author

oldbettie commented Jun 15, 2023

everything worked fine when deployed to supabase I am not importing anything for JSZip it seems to be something done under the hood. @gregnr Should I be cloning and running my functions in the edge-runtime rather then the supabase cli?

@northfacejmb
Copy link

I think I might be having a similar issue. Thank you for posting, I hope you're able to get to the bottom of it

@gregnr
Copy link
Member

gregnr commented Jun 16, 2023

@laktek sorry I didn't actually attempt on Deno Deploy - was making that assumption based on the original post, but I could be wrong.

@oldbettie the latest Supabase CLI uses edge-runtime under the hood when you run supabase functions serve.

I am not importing anything for JSZip it seems to be something done under the hood

Do you mind sharing the code you are running? Guessing you have another dependency that imports JSZip.

@oldbettie
Copy link
Author

oldbettie commented Jun 17, 2023

{
  "imports": {
    "postgres": "https://deno.land/x/postgres@v0.17.0/mod.ts",
    "puppeteer": "https://deno.land/x/puppeteer@16.2.0/mod.ts"
  }
}

here is my import map. I am alse importing serve directly into the functions as it seemed to be a bit faster

@gregnr
Copy link
Member

gregnr commented Jun 19, 2023

Thanks. Looks like puppeteer is likely the one importing JSZip:
https://github.com/lucacasonato/deno-puppeteer/blob/45b3162585b98ad8d54abeb56f48ecbb17c614eb/vendor/puppeteer-core/vendor/zip/mod.ts#L1

You can try overriding imports to force puppeteer to pull in JSZip with the bundle param (untested):

Edit for future viewers - this works:

{
  "imports": {
    "postgres": "https://deno.land/x/postgres@v0.17.0/mod.ts",
    "puppeteer": "https://deno.land/x/puppeteer@16.2.0/mod.ts"
  },
  "scopes": {
    "https://deno.land/x/puppeteer@16.2.0/vendor/puppeteer-core/vendor/zip/mod.ts": {
      "https://esm.sh/jszip@3.5.0": "https://esm.sh/jszip@3.5.0?bundle"
    }
  }
}

@byteDJINN
Copy link

I am also experiencing this exact issue. I'm following the example for puppeteer used in the documentation https://supabase.com/docs/guides/functions/examples/screenshots.
I tried to override the imports so my import_map.json looks like:

{
  "imports": {
    "std/server": "https://deno.land/std@0.177.0/http/server.ts",
    "puppeteer": "https://deno.land/x/puppeteer@16.2.0/mod.ts"
  },
  "scopes": {
    "puppeteer": {
      "https://esm.sh/jszip@3.5.0/": "https://esm.sh/jszip@3.5.0?bundle/"
    }
  }
}

However this had no effect, same error.

@oldbettie
Copy link
Author

@Elodin77 I have just been running the function individually and it seems to work. Bit annoying as I cant test the functions that call other functions locally but at least its something

@gregnr
Copy link
Member

gregnr commented Jun 20, 2023

Okay found some time to test this out - I was able to get it working using this import map:

{
  "imports": {
    "postgres": "https://deno.land/x/postgres@v0.17.0/mod.ts",
    "puppeteer": "https://deno.land/x/puppeteer@16.2.0/mod.ts"
  },
  "scopes": {
    "https://deno.land/x/puppeteer@16.2.0/vendor/puppeteer-core/vendor/zip/mod.ts": {
      "https://esm.sh/jszip@3.5.0": "https://esm.sh/jszip@3.5.0?bundle"
    }
  }
}

Or if you just want to override jszip everywhere:

{
  "imports": {
    "postgres": "https://deno.land/x/postgres@v0.17.0/mod.ts",
    "puppeteer": "https://deno.land/x/puppeteer@16.2.0/mod.ts",
    "https://esm.sh/jszip@3.5.0": "https://esm.sh/jszip@3.5.0?bundle"
  }
}

Worth noting this is a workaround - ideally we find out what's really happening here and see what is different between edge-runtime and Deno.

@andreespirela
Copy link
Collaborator

andrespirela@Andress-MBP edge-runtime % deno run --allow-all examples/empty-response/index.ts
error: Uncaught SyntaxError: The requested module '/v125/jszip@3.5.0/esnext/lib/readable-stream-browser.js' does not provide an export named 'default'
    at <anonymous> (https://esm.sh/v125/jszip@3.5.0/esnext/jszip.mjs:2:291)

@laktek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants