无法部署 Supabase Edge 功能(Stripe) - 相对导入路径“http”不以 / 或 ./ 或 ../ 为前缀

MIP*_*IPB 0 stripe-payments deno supabase

我尝试通过 Supabase 的 Edge Functions 连接到 Stripe,但我不断收到此错误:

相对导入路径“http”不以 / 或 ./ 或 ../ 为前缀

我一直在挖掘,它似乎与从 Typescript 到 Javascript 的捆绑有关,但我还没有找到解决方案。

我的代码和官方的一样: https: //github.com/supabase/supabase/blob/master/examples/edge-functions/supabase/functions/stripe-webhooks/index.ts

我注意到,如果删除 Stripe 导入,我可以进行部署,所以我猜它可能是相关的,但我无法理解为什么,因为其他导入(例如 Deno 的 Supabase 导入)可以正常工作。

谢谢!!

import { serve } from 'https://deno.land/std@0.132.0/http/server.ts'

// esm.sh is used to compile stripe-node to be compatible with ES modules.
import Stripe from 'https://esm.sh/stripe@10.13.0?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' },
  })
})```

Run Code Online (Sandbox Code Playgroud)

MIP*_*IPB 5

要解决此问题,您所需要做的就是在导入 URL 中添加“no-check”,如下所示:

https://esm.sh/stripe@11.0.0?target=deno&no-check
Run Code Online (Sandbox Code Playgroud)

来源:他们在 Github 上回答了我的问题:https ://github.com/supabase/supabase/issues/10543