MIPB
MIPB

Reputation: 2471

Can't deploy Supabase Edge Function (Stripe) - Relative import path "http" not prefixed with / or ./ or ../

I am trying to connect to Stripe through Supabase's Edge Functions, but I keep getting this error:

Relative import path "http" not prefixed with / or ./ or ../

I've been digging and it seems related to the bundling from Typescript to Javascript, but I have not found a solution yet.

My code is the same as the official: https://github.com/supabase/supabase/blob/master/examples/edge-functions/supabase/functions/stripe-webhooks/index.ts

I noticed that I can deploy if I delete the Stripe import, so I guess it could be related, but I can't understand why since other imports (like the Supabase import for Deno) work correctly.

Thanks!!

import { serve } from 'https://deno.land/[email protected]/http/server.ts'

// esm.sh is used to compile stripe-node to be compatible with ES modules.
import Stripe from 'https://esm.sh/[email protected]?target=deno&deno-std=0.132.0'

const stripe = Stripe(Deno.env.get('STRIPE_API_KEY'), {
  // This is needed to use the Fetch API rather than relying on the Node http
  // package.
  httpClient: Stripe.createFetchHttpClient(),
})
// This is needed in order to use the Web Crypto API in Deno.
const cryptoProvider = Stripe.createSubtleCryptoProvider()

console.log(`Function "stripe-webhooks" up and running!`)

serve(async (request) => {
  const signature = request.headers.get('Stripe-Signature')

  // First step is to verify the event. The .text() method must be used as the
  // verification relies on the raw request body rather than the parsed JSON.
  const body = await request.text()
  let receivedEvent
  try {
    receivedEvent = await stripe.webhooks.constructEventAsync(
      body,
      signature,
      Deno.env.get('STRIPE_WEBHOOK_SIGNING_SECRET'),
      undefined,
      cryptoProvider
    )
  } catch (err) {
    return new Response(err.message, { status: 400 })
  }
  console.log(`🔔 Event received: ${receivedEvent.id}`)

  // Secondly, we use this event to query the Stripe API in order to avoid
  // handling any forged event. If available, we use the idempotency key.
  const requestOptions =
    receivedEvent.request && receivedEvent.request.idempotency_key
      ? {
          idempotencyKey: receivedEvent.request.idempotency_key,
        }
      : {}

  let retrievedEvent
  try {
    retrievedEvent = await stripe.events.retrieve(receivedEvent.id, requestOptions)
  } catch (err) {
    return new Response(err.message, { status: 400 })
  }

  return new Response(JSON.stringify({ id: retrievedEvent.id, status: 'ok' }), {
    status: 200,
    headers: { 'Content-Type': 'application/json' },
  })
})```

Upvotes: 0

Views: 862

Answers (1)

MIPB
MIPB

Reputation: 2471

All you need to do to resolve this is add the "no-check" in the import url, as follows:

https://esm.sh/[email protected]?target=deno&no-check

Source: They answered my issue in Github: https://github.com/supabase/supabase/issues/10543

Upvotes: 5

Related Questions