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

调用Stripe处理支付时遭遇TS2349错误,寻求解决方案

解决Stripe TS2349调用签名错误问题

问题根源

你在前端项目中错误安装了后端专用的stripe包,这个包是给Node.js服务端使用的,需要通过类实例化才能调用方法,而前端浏览器环境应该使用Stripe官方提供的前端SDK @stripe/stripe-js。

解决步骤

  1. 卸载后端的stripe依赖
npm uninstall stripe
  1. 安装前端专用的Stripe SDK
npm install @stripe/stripe-js
  1. 正确的代码使用方式
import { loadStripe } from '@stripe/stripe-js';

// 替换为你的Stripe公钥
const stripePromise = loadStripe('pk_test_your_public_key');

// 示例支付触发逻辑
const handleInitiatePayment = async () => {
  const stripe = await stripePromise;
  if (!stripe) return;

  // 调用Stripe前端方法,比如跳转结账页
  const { error } = await stripe.redirectToCheckout({
    sessionId: 'your_checkout_session_id'
  });

  if (error) {
    console.error('支付初始化失败:', error);
  }
};

补充说明

后端的stripe包需要通过new Stripe(secretKey)实例化后才能调用API,而前端的@stripe/stripe-js采用异步加载的方式提供实例,类型定义完全适配前端TS环境,可直接解决你遇到的Type 'typeof import("stripe")' has no call signatures错误。

内容的提问来源于stack exchange,提问作者Mohd Ayan haque

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 02:57:14