SupabaseS
Supabase2mo ago
skamz

Can't use createClient in Edge Function (can't find tslib)

Below is my code. I have confirmed that the env vars are set. The error is specifically coming from the createClient line .. when I comment it out, there's no error.

The specific error is this:
event loop error: Error: Cannot find module 'tslib' Require stack: - /var/tmp/sb-compile-edge-runtime/node_modules/localhost/@supabase/functions-js/2.76.0/dist/main/FunctionsClient.js - /var/tmp/sb-compile-edge-runtime/node_modules/localhost/@supabase/functions-js/2.76.0/dist/main/index.js - /var/tmp/sb-compile-edge-runtime/node_modules/localhost/@supabase/supabase-js/2.76.0/dist/main/SupabaseClient.js - /var/tmp/sb-compile-edge-runtime/node_modules/localhost/@supabase/supabase-js/2.76.0/dist/main/index.js - /var/tmp/sb-compile-edge-runtime/node_modules/localhost/@supabase/supabase-js/2.76.0/dist/main/index.js at Function.Module._resolveFilename (node:module:619:15) at Function.Module._load (node:module:497:27) at Module.require (node:module:681:19) at require (node:module:818:16) at Object.<anonymous> (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/@supabase/functions-js/2.76.0/dist/main/FunctionsClient.js:4:17) at Object.<anonymous> (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/@supabase/functions-js/2.76.0/dist/main/FunctionsClient.js:132:4) at Module._compile (node:module:745:34) at loadMaybeCjs (node:module:770:10) at Object.Module._extensions..js (node:module:755:12) at Module.load (node:module:662:32)


And here is the code

import { createClient } from 'npm:@supabase/supabase-js@2';

Deno.serve(async (req)=>{
  const supabaseAdmin = createClient(
    Deno.env.get('SUPABASE_URL') ?? '', Deno.env.get('SUPABASE_SERVICE_ROLE_KEY') ?? ''
  );

  return new Response(JSON.stringify("it works"), {
    status: 200,
    headers: {
      'Content-Type': "application/json",
      'Connection': 'keep-alive'
    }
  });
});
Was this page helpful?