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)

Most upvoted comments

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 serve a try, after updating your deno.json to the following?

{
  "imports": {
    "@faker-js/faker": "npm:@faker-js/faker@^9.8.0",
    "@std/assert": "jsr:@std/assert@1",
    "#/": "./src/",
    "express": "npm:express@^5.1.0",
    "formatjs": "npm:formatjs@^0.1.1",
    "jose": "npm:jose@^6.0.11",
    "luxon": "npm:luxon@^3.6.1",
    "zod": "npm:zod@^3.25.67",
    "@db": "../../db/index.ts"
  },
  scopes: {
    "__local": {
      "__workspace": "../../../../../deno.json",
      "__libs": "../../../../../libs",
      "__domain": "../../../../../domain",
    }
  }
}

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.

    "__workspace": "../../../../../deno.json",
    "__libs": "../../../../../libs",

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

{
  "imports": {
    "@faker-js/faker": "npm:@faker-js/faker@^9.8.0"
  },
  "scopes": {
    "__workspace": {
      "__libs": "../../../../../libs"
    }
  }
}

@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 functions you’ll notice that the libs directory is outside of the workdir and is therefore excluded

To verify this you can attach a shell in the edge runtime docker container

now when I do this workaround by doing something like

{
  "imports": {
    "@faker-js/faker": "npm:@faker-js/faker@^9.8.0",
    "__workspace": "../../../../../deno.json",
    "__libs": "../../../../../libs",
    "__domain": "../../../../../domain",
    "@std/assert": "jsr:@std/assert@1",
    "#/": "./src/",
    "express": "npm:express@^5.1.0",
    "formatjs": "npm:formatjs@^0.1.1",
    "jose": "npm:jose@^6.0.11",
    "luxon": "npm:luxon@^3.6.1",
    "zod": "npm:zod@^3.25.67",
    "@db": "../../db/index.ts"
  }
}

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.8

The 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 remove the package.json from supabase/functions/example and do not add the package to the root package.json and it successfully compiles.

Have you tried removing the node_modules folder and running deno install or pnpm install command again? I think that method likely won’t work.

I just tried it and you are correct, seems that it needs to have the module cached in node_modules

okay I made some progress, if I add the following lines to the “imports” in deno.json

{
  "imports": {
    "@faker-js/faker": "npm:@faker-js/faker@^9.7.0",
    "@std/assert": "jsr:@std/assert@1",
    "#/": "./src/",
...

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-api experimental 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 @sweatybridge

If I implement the fix you suggested with --use-api I get the following

In 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

it appears to resolve the dependency when building it, but then the resulting function gives the following error at boot

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.

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)

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.json

{
  "imports": {
    "@faker-js/faker": "npm:@faker-js/faker@^9.7.0",
    "@std/assert": "jsr:@std/assert@1",
    "#/": "./src/",
    "__workspace": "../../../../../deno.json",
    "__libs": "../../../../../libs",
    "__domain": "../../../../../domain",
    "express": "npm:express@^5.1.0"
  }
}

and then add the package to a package.json

{
  "name": "sso",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "packageManager": "pnpm@10.8.1",
  "dependencies": {
    "@wovenlibs/core": "workspace:^"
  }
}

it appears to resolve the dependency when building it, but then the resulting function gives the following error at boot

worker boot error: invalid eszip v2
[
  {
    "boot_time": null,
    "cpu_time_used": null,
    "deployment_id": "zqcnafevawsfysnzwsjk_b1c8021e-047a-40bd-aa26-42a21f3e080a_30",
    "event_type": "BootFailure",
    "execution_id": "17ac207d-fc74-430f-83ab-db89e1bcd008",
    "function_id": "b1c8021e-047a-40bd-aa26-42a21f3e080a",
    "level": "error",
    "memory_used": [],
    "project_ref": "zqcnafevawsfysnzwsjk",
    "reason": null,
    "region": "ap-southeast-1",
    "served_by": "supabase-edge-runtime-1.67.3 (compatible with Deno v1.45.2)",
    "timestamp": "2025-04-16T00:58:16.181Z",
    "version": "30"
  }
]

(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:

worker boot error: [ERR_MODULE_NOT_FOUND] Cannot find module 'file:///var/tmp/sb-compile-edge-runtime/monorepo/libs/core/index.js' imported from 'file:///var/tmp/sb-compile-edge-runtime/monorepo/infra/supabase-core/supabase/functions/sso/main.ts'
InvalidWorkerCreation: worker boot error: [ERR_MODULE_NOT_FOUND] Cannot find module 'file:///var/tmp/sb-compile-edge-runtime/monorepo/libs/core/index.js' imported from 'file:///var/tmp/sb-compile-edge-runtime/monorepo/infra/supabase-core/supabase/functions/sso/main.ts'
    at async Function.create (ext:user_workers/user_workers.js:143:17)
    at async Object.handler (file:///var/tmp/sb-compile-edge-runtime/root/index.ts:157:22)
    at async respond (ext:runtime/http.js:202:16) {
  name: "InvalidWorkerCreation"
}

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

pnpx supabase functions deploy --use-api
Using workdir /Users/alitamoore/workspaces/monorepo/infra/supabase-core
WARN: no SMS provider is enabled. Disabling phone login
Uploading asset (sso): supabase/functions/sso/deno.json
Uploading asset (sso): supabase/functions/sso/main.ts
unexpected deploy status 400: {"message":"failed to create the graph\n\nCaused by:\n    Relative import path \"@wovenlibs/core\" not prefixed with / or ./ or ../ and not in import map from \"file:///tmp/user_fn_zqcnafevawsfysnzwsjk_b1c8021e-047a-40bd-aa26-42a21f3e080a_29/supabase/functions/sso/main.ts\"\n        at file:///tmp/user_fn_zqcnafevawsfysnzwsjk_b1c8021e-047a-40bd-aa26-42a21f3e080a_29/supabase/functions/sso/main.ts:9:24"}

If I implement the fix you suggested with --use-api I get the following

pnpx supabase functions deploy --use-api
Using workdir /Users/alitamoore/workspaces/monorepo/infra/supabase-core
WARN: no SMS provider is enabled. Disabling phone login
Uploading asset (sso): supabase/functions/sso/deno.json
Uploading asset (sso): supabase/functions/sso/main.ts
unexpected deploy status 400: {"message":"failed to create the graph\n\nCaused by:\n    Module not found \"file:///libs/core\".\n        at file:///tmp/user_fn_zqcnafevawsfysnzwsjk_b1c8021e-047a-40bd-aa26-42a21f3e080a_29/supabase/functions/sso/main.ts:9:24"}
Try rerunning the command with --debug to troubleshoot the error.

then without --use-api I get this

pnpx supabase functions deploy          
Using workdir /Users/alitamoore/workspaces/monorepo/infra/supabase-core
WARN: no SMS provider is enabled. Disabling phone login
Bundling Function: sso
Error: failed to create the graph

Caused by:
    Is a directory (os error 21)
        at file:///Users/alitamoore/workspaces/monorepo/infra/supabase-core/supabase/functions/sso/main.ts:9:24
error running container: exit 1
Try rerunning the command with --debug to troubleshoot the error.

Hey @nyannyacha 💚

… recently merged https://github.com/supabase/cli/pull/3417 seems related to this

Not really 😔 My PR only covers the module graph for local development and requires that imports need to be declared inside supabase/functions/[slug]/deno.json(c) or in the file defined at config.toml.

@alita-moore after looking your example, I could see that you have the following import_map config:

config.toml
[functions.example]
enabled = true
verify_jwt = true
import_map = "./functions/example/deno.json"

I’m not sure about Deno's workspaces neither @scope/ but based on my understanding the CLI will try to use this import_map to resolve your function deps. Also outside imports feat may requires the --use-api while deploying like described here


Possible fix:

Apply the following config to your supabase/functions/[slug]/deno.json(c)

{
    "imports":  {
        "@scope/": "../../../libs/"
    }
}

For large project with many functions, you can also define a global import_map.json then point it inside your config.toml. In a future release you’ll be also able to define importMap field directly from your supabase/functions/[slug]/deno.json(c)

Local development:

npx supabase@beta functions serve

Then deploy with:

npx supabase functions deploy --use-api 

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