edge-runtime: Self-hosted edge functions - Error when importing shared local files

Bug report

Describe the bug

Calling an edge function that imports local files from the _shared directory produces the following error:

{"msg":"InvalidWorkerCreation: worker boot error"}

Within the supabase-edge-functions container logs I see the following error:

Failed to load module: "file:///home/deno/functions/_shared/message.ts" - Invalid file path.
  Specifier: file:///home/deno/functions/_shared/message.ts

To Reproduce

  1. Follow the steps outlined under “Running Supabase” to download supabase and run using docker: https://supabase.com/docs/guides/self-hosting/docker#running-supabase
  2. Create the file /functions/_shared/message.ts:
export function message() {
  return 'Hello from Edge Functions!';
}
  1. Update /functions/hello/index.ts to import the function from that file:
import { serve } from "https://deno.land/std@0.177.1/http/server.ts"
import { message } from "../_shared/message.ts";

serve(async () => {
  return new Response(
    `${message()}`,
    { headers: { "Content-Type": "application/json" } },
  )
})
  1. Run docker compose down and docker compose up to ensure the new file is present within the container.
  2. Issue an http request to the endpoint: http://localhost:8000/functions/v1/hello

Expected behavior

I’m expecting the message Hello from Edge Functions! to be displayed, but instead, I see {"msg":"InvalidWorkerCreation: worker boot error"}

System information

  • OS: Docker container on Ubuntu 22 (EC2 on AWS)

Additional context

If I move the _shared directory underneath hello: /functions/hello/_shared/, and alter the import statement within /hello/index.ts to import { message } from "./_shared/message.ts";, then it works fine.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 18 (3 by maintainers)

Most upvoted comments

I have this issue too

I am having the same issue also. I use the same folder setup as per https://supabase.com/docs/guides/functions/quickstart#organizing-your-edge-functions

My folder structure is as so:

  • supabase
    • functions
      • _shared
        • admin.ts
      • my-handler-1
        • index.ts
      • my-handler-2
        • index.ts
      • import_map.json

My import_map.json looks like: { "imports": { "@supabase": "npm:@supabase/supabase-js@2.42.4", "@admin": "./_shared/admin.ts", } }

If I import in either of the functions index.ts files something from @admin e.g. import { myFunction } from "@admin";

My IDE (VSCode) is happy, but I get the following runtime error when the function is invoked:

Using supabase-edge-runtime-1.45.2 (compatible with Deno v1.40.3) serving the request with /home/deno/functions/my-handler-1 serving the request with /home/deno/functions/my-handler-1 failed to load 'file:///home/deno/_shared/admin.ts': Module not found "file:///home/deno/_shared/admin.ts". An error has occured InvalidWorkerCreation: worker boot error failed to load 'file:///home/deno/_shared/admin.ts': Module not found "file:///home/deno/_shared/admin.ts". at async UserWorker.create (ext:sb_user_workers/user_workers.js:141:15) at async Object.handler (file:///home/deno/main/index.ts:147:22) at async handleHttp (ext:sb_core_main_js/js/http.js:112:15) { name: "InvalidWorkerCreation" }

I have tired running the function by specifying the import_map.json file as an arg, by config.toml and also without specifying anything about an import_map.json file and I can’t get it to work.

e,g. npx supabase functions serve my-handler-1 --env-file ./.env --import-map ./supabase/functions/import_map.json

Only by moving the admin.ts file into the my-handler-1 folder makes the import work, however this obviously makes it unable to be shared to my-handler-2/index.ts

Has anyone else been able to share a local module between 2 functions successfully? If so, could you please post an example.

I have the same issue. Running 1.38.0. _shared is in the functions folder

Once I moved it into the folder where the function resides, the issue got resolved.

Here is the detailed error:


Download https://cdn.skypack.dev/pin/class-transformer@v0.5.1-aR2pMa59U5FgYZvFaH0Z/mode=imports,min/optimized/class-transformer.js?dts
Uncaught SyntaxError: Invalid or unexpected token
    at file:///home/deno/functions/_shared/models/person-form-answer-option.ts:3:3
An error has occured
InvalidWorkerCreation: worker boot error
    at async UserWorker.create (ext:sb_user_workers/user_workers.js:141:15)
    at async Server.<anonymous> (file:///home/deno/main/index.ts:129:20)
    at async #respond (https://deno.land/std@0.182.0/http/server.ts:220:18) {
  name: "InvalidWorkerCreation"
}

Here is excerpt from my person-form-answer-option.ts:

import {
  Expose,
} from "https://cdn.skypack.dev/pin/class-transformer@v0.5.1-aR2pMa59U5FgYZvFaH0Z/mode=imports,min/optimized/class-transformer.js?dts";

export class PersonFormAnswerOption {
  @Expose()
  public id!: string;

same issue 😦