You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法部署Supabase Edge Function(Stripe):相对导入路径"http"未加前缀

Supabase Edge Functions 连接 Stripe 报错求助

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

我尝试用Supabase的Edge Functions对接Stripe,但一直碰到上面这个错误。排查后发现问题和TypeScript转JavaScript的打包流程有关,但还没找到解决办法。

我的代码和官方示例完全一致,删掉Stripe的导入就能正常部署,所以推测问题出在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' },
  })
})

内容的提问来源于stack exchange,提问作者MIPB

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 23:00:56