running supabase functions serve fails. running supabase functions serve <name> causes postgres connection to fail
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
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/[email protected]/esnext/lib/readable-stream-browser.js' does not provide an export named 'default'
at https://esm.sh/v125/[email protected]/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/[email protected]/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.
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/[email protected]?bundle';
which tells esm.sh to bundle all dependencies into a single JS file.
Let me know if this helps.
@gregnr Did the import work when function was deployed to Deno Deploy? Will try to reproduce it.
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?
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
@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.
{
"imports": {
"postgres": "https://deno.land/x/[email protected]/mod.ts",
"puppeteer": "https://deno.land/x/[email protected]/mod.ts"
}
}
here is my import map. I am alse importing serve directly into the functions as it seemed to be a bit faster
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/[email protected]/mod.ts",
"puppeteer": "https://deno.land/x/[email protected]/mod.ts"
},
"scopes": {
"https://deno.land/x/[email protected]/vendor/puppeteer-core/vendor/zip/mod.ts": {
"https://esm.sh/[email protected]": "https://esm.sh/[email protected]?bundle"
}
}
}
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/[email protected]/http/server.ts",
"puppeteer": "https://deno.land/x/[email protected]/mod.ts"
},
"scopes": {
"puppeteer": {
"https://esm.sh/[email protected]/": "https://esm.sh/[email protected]?bundle/"
}
}
}
However this had no effect, same error.
@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
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/[email protected]/mod.ts",
"puppeteer": "https://deno.land/x/[email protected]/mod.ts"
},
"scopes": {
"https://deno.land/x/[email protected]/vendor/puppeteer-core/vendor/zip/mod.ts": {
"https://esm.sh/[email protected]": "https://esm.sh/[email protected]?bundle"
}
}
}
Or if you just want to override jszip everywhere:
{
"imports": {
"postgres": "https://deno.land/x/[email protected]/mod.ts",
"puppeteer": "https://deno.land/x/[email protected]/mod.ts",
"https://esm.sh/[email protected]": "https://esm.sh/[email protected]?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.
andrespirela@Andress-MBP edge-runtime % deno run --allow-all examples/empty-response/index.ts
error: Uncaught SyntaxError: The requested module '/v125/[email protected]/esnext/lib/readable-stream-browser.js' does not provide an export named 'default'
at <anonymous> (https://esm.sh/v125/[email protected]/esnext/jszip.mjs:2:291)
@laktek
- This import issue also happens on the latest version of Deno.
- https://esm.sh/v125/[email protected]/esnext/lib/readable-stream-browser.js shows there is not default imports even though the code is trying to access a default module which is why the error is being thrown.
Also getting this issue which works on a different project. Went back and used the same function I wrote on another project and I get this error when trying to serve:
Could not resolve './models/EmailJSResponseStatus' from 'file:///tmp/sb-compile-edge-runtime/node_modules/localhost/@emailjs/nodejs/4.0.4/mjs/index.js'. An error has occured InvalidWorkerCreation: worker boot error Could not resolve './models/EmailJSResponseStatus' from 'file:///tmp/sb-compile-edge-runtime/node_modules/localhost/@emailjs/nodejs/4.0.4/mjs/index.js'. at async UserWorker.create (ext:sb_user_workers/user_workers.js:144:15)
It's been almost a year. Is there really no official response or at least acknowledgment of this?