Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Self-hosted edge functions - Error when importing shared local files #149

Open
neuquen opened this issue Jul 27, 2023 · 14 comments · Fixed by #154
Open

Self-hosted edge functions - Error when importing shared local files #149

neuquen opened this issue Jul 27, 2023 · 14 comments · Fixed by #154
Labels
bug Something isn't working released

Comments

@neuquen
Copy link

neuquen commented Jul 27, 2023

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/[email protected]/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.

@neuquen neuquen added the bug Something isn't working label Jul 27, 2023
@neuquen neuquen changed the title Self-hosted edge functions - Error when importing local files Self-hosted edge functions - Error when importing shared local files Jul 27, 2023
@kiwicopple kiwicopple transferred this issue from supabase/supabase Jul 30, 2023
@AndriyBas
Copy link

I have the same issue

@github-actions
Copy link

github-actions bot commented Aug 2, 2023

🎉 This issue has been resolved in version 1.8.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@ginsudev
Copy link

I have this issue too

@fraktalize
Copy link

I also have this issue!

@laktek
Copy link
Contributor

laktek commented Oct 11, 2023

@ginsudev @fraktalize Are you experiencing the issue when running via Supabase CLI? Have you tried upgrading to the latest version of the CLI?

If you're running edge-runtime directly, can you share your setup so I can try to reproduce the issue.

@drobles-atdev
Copy link

having the same issue today, this is is not fixed yet.

@jb-thery
Copy link

same issue :(

@thewebbeckons
Copy link

Also same issue; just updated the CLI.

supabase-edge-runtime-1.33.5

@laktek
Copy link
Contributor

laktek commented Feb 13, 2024

@jb-thery @thewebbeckons Are you trying to import from _shared directory in supabase/functions? What's the exact error message you get? Also, it would be handy if you can share the import statements in your function so I can try to reproduce it.

@laktek laktek reopened this Feb 13, 2024
@thewebbeckons
Copy link

@laktek Seems like mine was something different just reporting the same error message. Can disregard my comment; everything is resolved on my end.

@antonio-petrov
Copy link

antonio-petrov commented Mar 8, 2024

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/[email protected]/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/[email protected]/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/[email protected]/mode=imports,min/optimized/class-transformer.js?dts";

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

@rookledookle
Copy link

having similar issues

@questicles
Copy link

questicles commented May 9, 2024

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/[email protected]", "@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.

@s-borah
Copy link

s-borah commented May 14, 2024

Same issue, please fix it or suggest solution please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.