条纹方法表达式不是函数类型
Stripe method expression is not of Function type
我使用 npm install --save stripe
安装了 stripe,但是当我添加行 const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
时,我收到一条警告,说 stripe 方法表达式不是函数类型。 require('stripe') 有下划线。当我尝试 运行 时,出现错误
You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g. 'Authorization: Bearer YOUR_SECRET_KEY').
我什至尝试用实际密钥替换 process.env.STRIPE_SECRET_KEY,但它仍然给我这个错误。
要在 React 中使用 stripe,您必须使用 loadstipe
并且不能在组件内部使用 require
。
首先安装这个包:
npm install --save @stripe/react-stripe-js @stripe/stripe-js
然后使用 loadstripe 加载它:
import {loadStripe} from '@stripe/stripe-js';
// Make sure to call `loadStripe` outside of a component’s render to avoid
// recreating the `Stripe` object on every render.
const stripePromise = loadStripe('pk_test_HvEeju8Kg8pqDFSjQQyyxGDb');
请阅读 stripe 文档以获取更多信息:https://stripe.com/docs/stripe-js/react
我可以通过在 require('stripe')(process.env.STRIPE_SECRET_KEY);
之前添加 require('dotenv').config();
来修复它。我仍然收到警告,但现在可以使用了。
我使用 npm install --save stripe
安装了 stripe,但是当我添加行 const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
时,我收到一条警告,说 stripe 方法表达式不是函数类型。 require('stripe') 有下划线。当我尝试 运行 时,出现错误
You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g. 'Authorization: Bearer YOUR_SECRET_KEY').
我什至尝试用实际密钥替换 process.env.STRIPE_SECRET_KEY,但它仍然给我这个错误。
要在 React 中使用 stripe,您必须使用 loadstipe
并且不能在组件内部使用 require
。
首先安装这个包:
npm install --save @stripe/react-stripe-js @stripe/stripe-js
然后使用 loadstripe 加载它:
import {loadStripe} from '@stripe/stripe-js';
// Make sure to call `loadStripe` outside of a component’s render to avoid
// recreating the `Stripe` object on every render.
const stripePromise = loadStripe('pk_test_HvEeju8Kg8pqDFSjQQyyxGDb');
请阅读 stripe 文档以获取更多信息:https://stripe.com/docs/stripe-js/react
我可以通过在 require('stripe')(process.env.STRIPE_SECRET_KEY);
之前添加 require('dotenv').config();
来修复它。我仍然收到警告,但现在可以使用了。