S
Supabase5d ago
SD

Supabase edge functions and local imports

I'm struggling with figuring out the best way to deploy edge functions which take a dependency on classes or methods defined elsewhere in my repository. I see a lot of posts online around _shared folders, deno.json and import_map. How do I use deno.json for a local import from another place in my repo? Do I need to modify the supabase function deploy <function_name> CLI command in any way? The issue I'm running into now is something like -
unexpected deploy status 400: {"message":"failed to create the graph\n\nCaused by:\n Module not found \"file:///tmp/user_fn_gmniqteyvuvjvhvaqbxi_7aea3757-1209-4749-8f2e-0af891505194_7/source/supabase/functions/_shared/baml_client/async_client\".\n at file:///tmp/user_fn_gmniqteyvuvjvhvaqbxi_7aea3757-1209-4749-8f2e-0af891505194_7/source/supabase/functions/generate-feedback/index.ts:3:19"}
unexpected deploy status 400: {"message":"failed to create the graph\n\nCaused by:\n Module not found \"file:///tmp/user_fn_gmniqteyvuvjvhvaqbxi_7aea3757-1209-4749-8f2e-0af891505194_7/source/supabase/functions/_shared/baml_client/async_client\".\n at file:///tmp/user_fn_gmniqteyvuvjvhvaqbxi_7aea3757-1209-4749-8f2e-0af891505194_7/source/supabase/functions/generate-feedback/index.ts:3:19"}
6 Replies
tristanrhodes
tristanrhodes5d ago
I’ve used a shared file with cors settings, but I don’t have it in front of me
Ankur
Ankur5d ago
@SD but supabase doesn't recommand to use the global deno.json file . recommand to use the seperate file for each edge function
No description
SD
SDOP5d ago
Right I saw that. I think maybe my understanding of how the packaging is done for supabase function deploy is insufficient, or I don't know enough about Deno. I also realized that what I wanted to import itself has some imports done without the typescript .ts extension (like import _ from './file'. And deno doesn't allow that
inder
inder5d ago
You can have a dir structure like this. For example you can import any export from cors.ts file.
No description
inder
inder5d ago
Also, .ts extension in import statement is necessary
SD
SDOP4d ago
Noted, thanks!

Did you find this page helpful?