(cd npm-lib && npm install && npx tsc --project tsconfig.json)
- There should now be a compiled version of the library at
npm-lib/dist
(cd server/supabase/functions && npm install)
(cd server/supabase/functions && npm run build)
- There should now be a
node_modules
folder and anpm-lib
folder atserver/supabase/functions
.
(cd server && deno run --allow-read --allow-env supabase/functions/core-data.ts)
- Should output something along the lines of
Hello from core data { CORE_DATA: { foo: [ 1, 2, 3 ] }, update: [Function: update] }
- Install Supabase 1.7.0:
(cd server && npm install)
(cd server && npx supabase start)
(cd server && npx supabase functions serve hello-npm --debug)
- The function should now be available, you may test it using
curl -i --location --request POST 'http://localhost:54321/functions/v1/' --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24ifQ.625_WdcF3KHqz5amU0x2X5WWHP-OEs_4qj0ssLNHzTs' --header 'Content-Type: application/json' --data '{"name":"Functions"}'
- Uncomment lines marked with
// ### Uncomment after boot
inserver/supabase/functions/hello-npm/index.ts
- The function will automatically be reloaded, the output should read:
Hello from core data { CORE_DATA: { foo: [ 1, 2, 3 ] }, update: [Function: update] }
Hello from Functions, core data is { foo: [ 1, 2, 3 ] }
- If you re-execute the above
curl
-command, you will see that the invocation now returns{"foo":"Functions"}
. Thereforeimmer.js
has been loaded just fine and is working as intended.
- Stop the previous
functions serve
instance. - Start it again:
(cd server && npx supabase functions serve hello-npm --debug)
- This will fail with loads of errors along the lines of the following:
TS2339 [ERROR]: Property 'loadavg' does not exist on type 'typeof Deno'. 'Deno.loadavg' is an unstable API. Did you forget to run with the '--unstable' flag?
return Deno.loadavg();
~~~~~~~
at https://deno.land/[email protected]/node/os.ts:171:15
TS2339 [ERROR]: Property 'osRelease' does not exist on type 'typeof Deno'. 'Deno.osRelease' is an unstable API. Did you forget to run with the '--unstable' flag?
return Deno.osRelease();
~~~~~~~~~
at https://deno.land/[email protected]/node/os.ts:185:15
TS2339 [ERROR]: Property 'systemMemoryInfo' does not exist on type 'typeof Deno'. 'Deno.systemMemoryInfo' is an unstable API. Did you forget to run with the '--unstable' flag?
return Deno.systemMemoryInfo().total;
~~~~~~~~~~~~~~~~
at https://deno.land/[email protected]/node/os.ts:231:15