supabase: fail to deploy functions that use deno workspace packages
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
functions deploy fails to deploy functions with workspace dependencies
To Reproduce
See the following project: https://codesandbox.io/p/devbox/elastic-chatterjee-forked-6496py?workspaceId=ws_VGZMLHNu2hWPYZLrXEYbsU
you can see the supabase function in supabase/functions/example. Attempting to deploy this will fail. However deno run index.ts works as expected
Expected behavior
pnpx supabase functions deploy deploys the function and resolves the workspace dependencies in the same way that deno does.
Screenshots
If applicable, add screenshots to help explain your problem.
System information
- Version of supabase-js: 2.20.12
- Version of Node.js: v22.14.0
Additional context
note that it fails with the following error:
Relative import path "@wovenlibs/core" not prefixed with / or ./ or ../ and not in import map
because deno can resolve the workspace packages without a scheme. But it seems supabase cannot resolve workspace files in the same way.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 39 (18 by maintainers)
I’ve confirmed that hte edge runtime container now includes the expected source files, so that problem appears to be fixed. I haven’t been able to confirm I can get the function running though because it’s not detecting dependencies of dependencies. For example if the function in the example that I shared imported from zod which was only included via the package.json in the libs/lib package. But this seems like a different issue.
I think it’s safe to close this issue. Thank you for your help!
Thanks for confirming. I will close this issue then.
Resolving nested dependencies needs to wait for proper deno 2.0 support. Functions team will give you an update in the future.
@alita-moore could you give
npx supabase@beta functions servea try, after updating your deno.json to the following?I’ve verified this on your sandbox. https://codesandbox.io/p/devbox/tender-goldberg-zz898x
Ok I see what you mean now. So you are using underscore prefixed imports as a workaround to mount additional directories to edge runtime container. ie.
Since we removed traversing of unused imports, this became a breaking change for your use case.
I can update CLI to handle the old behaviour using scopes block instead. for eg. in deno.json
@sweatybridge
https://codesandbox.io/p/devbox/tender-goldberg-zz898x
or if you prefer local development
workspace2.zip
do recreate you need to go into the example folder then run
pnpx supabase serve functionsyou’ll notice that the libs directory is outside of the workdir and is therefore excludedTo verify this you can attach a shell in the edge runtime docker container
now when I do this workaround by doing something like
the docker container is no longer copying the relevant libs and domain directory, it’s only copying the specified paths under the workdir path of the supabase root. Why was this behavior changed? This is getting quite frustrating!
Hi @alita-moore 💚 The short answer is not yet. But is estimated to be within the next 4 weeks Pls check this comment for a more detailed explanation.
Supabase CLI 2.22.8The pathing is correct and it works locally (also inconsistent though)
I opened a follow up issue in the deno repo regarding this problem: https://github.com/denoland/deno/issues/28942
I just tried it and you are correct, seems that it needs to have the module cached in node_modules
Actually, this part is unnecessary from the perspective of edge runtime itself — even if these things are not declared, it should work properly, but I think it’s just that because the volume mount method of cli prevents the edge runtime container from finding the parent folder.
by the way, it’s worth noting that the default build system using docker is including files outside of the functions directory, which is good news. Does this mean the
--use-apiexperimental feature is not necessary anymore? especially if there were some way to resolve which resources were being used by deno to include them in the build automatically. cc @sweatybridgeIn this case, the backend that performs bundling is on the Supabase side and does not yet support Deno 2, so this is expected behavior.
cc @laktek
As mentioned above, Supabase Edge Functions does not yet support Deno 2. This is expected behavior because function bundles made in the latest version of the edge runtime (v1.68.0-develop.13, Deno 2) cannot yet be loaded by the service.
Note: This bug turns out to also occur in the
deno compile <SCRIPT_ARG>command, which is the original implementation of the bundling logic of the edge runtime.okay I made some progress, if I add the following lines to the “imports” in
deno.jsonand then add the package to a package.json
it appears to resolve the dependency when building it, but then the resulting function gives the following error at boot
(edit: I’m noticing that the deno version here is v1, is there a way to upgrade the deno on the edge environment to v2?)
it would be nice if I could also get rid of the package.json as it seems unnecessary in this case. note that when I run this locally with pnpx supabase functions serve it seems to copy the files correctly into the container but then I get this error when it runs:
which is odd because the package.json defines where it should be looking for the index file (i.e.
./dist/src/index.js)@kallebysantos when I use the --use-api I get the following error
If I implement the fix you suggested with --use-api I get the following
then without --use-api I get this
Hey @nyannyacha 💚
Not really 😔 My PR only covers the module graph for local development and requires that
importsneed to be declared insidesupabase/functions/[slug]/deno.json(c)or in the file defined atconfig.toml.@alita-moore after looking your example, I could see that you have the following
import_mapconfig:config.toml
I’m not sure about
Deno's workspacesneither@scope/but based on my understanding the CLI will try to use thisimport_mapto resolve your function deps. Also outside imports feat may requires the--use-apiwhile deploying like described herePossible fix:
Apply the following config to your
supabase/functions/[slug]/deno.json(c)Local development:
Then deploy with:
I hope that it helps 💚
Hello @alita-moore 😄 Can you tell me what version of the CLI you are using? @kallebysantos recently merged a PR seems related to this, and I’d like to bisect if it’s a separate issue.
@nyannyacha might have some idea on this error
also related to https://github.com/supabase/cli/issues/3047