This is the code using CommonJS that works:
const { createClient } = require('@supabase/supabase-js');
exports.handler = async (context, event, callback) => {
const supabaseUrl = 'https://teuytpiznwvvdhrkycqb.supabase.co';
const supabase = createClient(supabaseUrl, context.SUPABASE_KEY);
This is the code using ESM that throws the error:
export const handler = async (context, event, callback) => {
const { createClient } = await import('@supabase/supabase-js');
const supabaseUrl = 'https://teuytpiznwvvdhrkycqb.supabase.co';
const supabase = createClient(supabaseUrl, context.SUPABASE_KEY);
If I move the import out of my function then Twilio throws the same error
const { createClient } = import('@supabase/supabase-js');
export const handler = async (context, event, callback) => {
// const { createClient } = await import('@supabase/supabase-js');
const supabaseUrl = 'https://teuytpiznwvvdhrkycqb.supabase.co';
const supabase = createClient(supabaseUrl, context.SUPABASE_KEY);
Twilio UI is using Node v18
I also have this code that does work and Twilio Docs say ESM is supported
exports.handler = async function (context, event, callback) { const twilioClient = context.getTwilioClient();