edge-runtime
edge-runtime copied to clipboard
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
- Follow the steps outlined under "Running Supabase" to download supabase and run using docker: https://supabase.com/docs/guides/self-hosting/docker#running-supabase
- Create the file
/functions/_shared/message.ts:
export function message() {
return 'Hello from Edge Functions!';
}
- Update
/functions/hello/index.tsto 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" } },
)
})
- Run
docker compose downanddocker compose upto ensure the new file is present within the container. - 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.
I have the same issue
:tada: This issue has been resolved in version 1.8.2 :tada:
The release is available on GitHub release
Your semantic-release bot :package::rocket:
I have this issue too
I also have this issue!
@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.
having the same issue today, this is is not fixed yet.
same issue :(
Also same issue; just updated the CLI.
supabase-edge-runtime-1.33.5
@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 Seems like mine was something different just reporting the same error message. Can disregard my comment; everything is resolved on my end.
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;
having similar issues
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
- _shared
- functions
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.
Same issue, please fix it or suggest solution please.
Not sure if this issue is directly related, but I get this error when importing json file locally using the debugger:
Using supabase-edge-runtime-1.54.6 (compatible with Deno v1.43.0)
serving the request with /{~~~masked~~~}/supabase/functions/create_notification
Debugger listening on ws://0.0.0.0:8083/ws/b1c0f068-52c0-4f8c-81fe-24c19aa84c30
Visit chrome://inspect to connect to the debugger.
Worker is waiting for debugger to connect.
Uncaught SyntaxError: Unexpected non-whitespace character after JSON at position 89 (line 3 column 2)
An error has occured
InvalidWorkerCreation: worker boot error Uncaught SyntaxError: Unexpected non-whitespace character after JSON at position 89 (line 3 column 2)
at async UserWorker.create (ext:sb_user_workers/user_workers.js:155:15)
at async Object.handler (file:///home/deno/index.ts:147:22)
at async respond (ext:sb_core_main_js/js/http.js:163:14) {
name: "InvalidWorkerCreation"
}
using this code:
import serviceAccount from "../test.json" with { type: "json" };
with this test file
{
"project_id": "projectid", "private_key": "abcd", "client_email": "[email protected]"
}
Seems like something do with the end of file character (line 3 column 2)... but there's nothing there... i have tried adding an extra line or deleting any whitespace after it, still fires the same issue.
This only occurs when using the debugger, or the ''--inspect" flag.
same issue here