cli: `serve ` command errors when importing local files

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

When running supabase functions serve, if a function imports a local file specified in the import_map.json file that is outside the function folder, the command fails. When running an edge-function using the deno run --allow-all ./supabase/functions/my-function/index.ts command, one is able to test and run the function.

...
Download https://deno.land/x/jose@v4.4.0/lib/check_p2s.ts
Download https://deno.land/x/jose@v4.4.0/runtime/bogus.ts
Download https://deno.land/x/jose@v4.4.0/runtime/subtle_rsaes.ts
error: Module not found "file:///home/deno/lib/cors.ts".
    at file:///home/deno/functions/my-function/index.ts:9:29
2023/05/12 11:18:51 Sent Header: Host [docker]
2023/05/12 11:18:51 Sent Header: User-Agent [Go-http-client/1.1]
2023/05/12 11:18:51 Send Done
2023/05/12 11:18:51 Recv First Byte

To Reproduce

  1. Create a new edge function directory and index.ts inside the ./supabase/functions dir.
  2. Create a util file outside the new function directory. For example, inside ./supabase/lib/cors.ts.
  3. Import cors.ts inside the index.ts file.
// index.ts
import cors from '@backend/lib/cors.ts';
...
  1. Specify the path to the util file in import_map.json relative to the location of the import_map.json file
// this file is inside ./supabase
{
  "imports": {
    "@backend/": "./",
}
  1. Run supabase functions serve my-function

Expected behavior

The local edge function runs successfully as it does in deno.

Screenshots

N/A

System information

  • OS: [e.g. macOS, Windows]
  • Browser (if applies) [e.g. chrome, safari]
  • Version of supabase-js: [e.g. 2.21.0]
  • Version of supabase cli: [e.g. 1.57.3]
  • Version of Node.js: [e.g. 16]

Additional context

Add any other context about the problem here.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 25 (10 by maintainers)

Most upvoted comments

If anyone came here with this issue, I was struggling with trying to get import_map to work, only to discover Deno stopped using import maps since 1.30:

https://docs.deno.com/runtime/manual/getting_started/configuration_file#imports-and-scopes

Since version 1.30, the deno.json configuration file acts as an import map for resolving bare specifiers.

So now you put your import aliases in the imports object in deno.json.

We have to keep deno relay for the time being while we iron out other issues with edge runtime. Once that’s completed, we will default functions serve <name> to use the same runtime.

Ah! ok that works! I do see the modules folder now! Still having trouble with some external does now that don’t download from CDN but seems like the local files issue is solved! Some notes though:

  • The folder does not appear when one runs supabase functions server <FUNCTION_NAME>
  • I still see the container image is supabase_deno_relay, I expected it would be using the newer edge-runtime container.

Now that you mention docker, let me try deleting and recreating the stack…