cli icon indicating copy to clipboard operation
cli copied to clipboard

Edge functions are nearly impossible to write if project directory is a monorepo

Open evelant opened this issue 1 year ago • 9 comments

Describe the bug

This may not be actionable by the Supabase team since it may be a bug in Deno but I at least wanted to bring it up here for visibility. Since Supabase by default puts the edge functions project in a sub-directory this breaks the ability to edit Deno code with Deno LSP if there is a root package.json.

For more detail see the issue filed at vscode_deno: https://github.com/denoland/vscode_deno/issues/878

To Reproduce Steps to reproduce the behavior:

  1. Create a supabase project
  2. Use a root package.json for a monorepo setup
  3. Observe that editing edge function code doesn't work correctly due to Deno LSP conflicting with TSServer

Expected behavior Default project structure should try to work around Deno's quirks. Or more ideally allow building edge functions with a less problematic runtime such as Bun.

Screenshots

Desktop (please complete the following information):

  • OS: macOS
  • Browser (if applicable) N/A
  • Version of CLI N/A
  • Version of supabase-js (if applicable) N/A
  • Version of Node.js (if applicable) N/A

Additional context

evelant avatar Jul 11 '23 13:07 evelant

@evelant we will look into providing customization options for the project structure.

Also, would you be interested in jumping on a quick call with me to summarize your monorepo setup and how you use edge functions? It will help us to design a better solution to handle different use cases.

laktek avatar Jul 16 '23 23:07 laktek

@laktek Sure I could chat tomorrow, just let me know when

evelant avatar Jul 17 '23 00:07 evelant

@evelant are you still having this issue? This setup seems to be working as expected for me.

soedirgo avatar Jul 27 '23 11:07 soedirgo

I have a mono repo with supabase, a react-app (typescript vite), and a scripts (typescript node) folder for some.

In vscode I can open the root project and edit the supabase/functions app OR the react-app. However, once I start editing the react-app, the deno files for some reason start getting picked up by the ts LSP instead of the deno LSP.

I think there's probably some way to configure vscode workspaces...

ChuckJonas avatar Jul 28 '23 14:07 ChuckJonas

CLI now has an option to setup vscode workspace for edge functions when running supabase init. Does it work for you?

sweatybridge avatar Nov 09 '23 04:11 sweatybridge

@sweatybridge Unfortunately not, I already tried the vscode workspace trick. It seems there are multiple bugs in vscode_deno which unfortunately don't seem to be getting any attention from the Deno team. They've seen no movement for at least the last 3 months. https://github.com/denoland/vscode_deno/issues/878 https://github.com/denoland/vscode_deno/issues/967 https://github.com/denoland/vscode_deno/issues/873 https://github.com/denoland/vscode_deno/issues/488

Has the Supabase team considered supporting something other than Deno for the edge runtime? I realize you're pretty invested in it given the use of Deno deploy and all of the custom tooling you've had to build to make it work, but Deno is just so incredibly painful to work with.

I've had to code edge functions exclusively without type checking. Import maps break all the time and must be manually kept in sync with package.json versions used in shared code. I get random 502 errors on clients with no logs indicating a problem. I get random slow response times. Packages imported from esm.sh working at all is a crapshoot. The editor support is of abysmal quality (this issue)... and so on.

I've wasted so much valuable time fighting with Deno for what should be a simple use case. I have some code in a shared package in a standard pnpm monorepo that uses some libraries from npm. I need to use that code in fairly simple edge fns. Doing that is incredibly much harder than it should be.

Bun would be a fantastic alternative. It just works with modern code and ecosystem and has batteries included tooling for seemingly a lot of the stuff you've had to hack into working with Deno (like bundling local shared code).

evelant avatar Nov 09 '23 15:11 evelant

I would also like to voice my frustrations in regard to using edge functions in a monorepo with any sort of complexity. I'd like to import code I have in packages/* but it's nearly impossible. Deno was a mistake. Forced to use Vercel instead.

erickreutz avatar Jan 05 '24 22:01 erickreutz

I really agree. Edge functions in Deno in my repo has been the single biggest pain with using Supabase. I really wish we could just have node edge functions, it would make the project so much simpler to maintain

otang avatar Jan 26 '24 16:01 otang