简体   繁体   English

未捕获(承诺)错误:提供给 `Elements` 的道具 `stripe` 无效。 我们建议使用来自 `@stripe/stripe-js` 的 `loadStripe` 实用程序

[英]Uncaught (in promise) Error: Invalid prop `stripe` supplied to `Elements`. We recommend using the `loadStripe` utility from `@stripe/stripe-js`

I'm SO frustrated.我很沮丧。 I'm literally implementing straight from the Stripe Docs, and I keep getting the error我实际上是直接从 Stripe Docs 实施的,但我不断收到错误消息

Error: Invalid prop 'stripe' supplied to 'Elements'. We recommend using the 'loadStripe' utility from '@stripe/stripe-js'

... but I am! ... 但我是! What is wrong with this script?这个脚本有什么问题? I've searched everywhere, and can not find any reason why I'm getting this error.我到处搜索,但找不到任何我收到此错误的原因。

import React from "react"
import PropTypes from "prop-types"
import {loadStripe} from '@stripe/stripe-js';
import {CardElement, Elements, useElements, useStripe} from '@stripe/react-stripe-js';

const stripePromise = loadStripe('pk_test_yesItsMyRealKey')

class MembershipCheckout extends 

React.Component {
  render() {
    return(
        <Elements stripe={stripePromise}>
        </Elements>
    )
  }
}


export default MembershipCheckout;

package.json包.json

"@stripe/react-stripe-js": "^1.1.2",
"@stripe/stripe-js": "^1.11.0",

Not sure if it matters, but i'm using Rails 6, with react-rails and webpacker不确定它是否重要,但我使用的是 Rails 6,带有 react-rails 和 webpacker

Please check if you have loaded the stripe script from your index.html.请检查您是否从 index.html 加载了条带脚本。 if so, please remove it.如果是这样,请删除它。 The method you use works for react library only and creates incompatibility if you load another Stripe library via index.html.您使用的方法仅适用于 react 库,如果您通过 index.html 加载另一个 Stripe 库,则会导致不兼容。

Wow I'm a freaking moron.哇,我真是个白痴。 I still had <script type="text/javascript" src="https://js.stripe.com/v2/"></script>我还有<script type="text/javascript" src="https://js.stripe.com/v2/"></script>

in my app layout header, which is what was causing this error.在我的应用程序布局标题中,这是导致此错误的原因。 This error message is misleading.此错误消息具有误导性。 This link helped me realize that 这个链接帮助我意识到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM