简体   繁体   English

当我使用 Next.js 加载 Stripe 并发生构建错误时

[英]When I load Stripe with Next.js and build error occurs

When I use Stripe in Next.js and "yarn build", I get an error.当我在 Next.js 和“yarn build”中使用 Stripe 时,出现错误。

During local development with yarn dev, it works without any error.在使用 yarn dev 进行本地开发期间,它可以正常运行。

i cant understand why this is happen.我不明白为什么会这样。

 function CheckoutForm(props) {
  const [redirect, setRedirect] = useState('true');
  const { bodyAdquire } = useAppContext();
  const router = useRouter();

  let teamName = process.env.NEXT_PUBLIC_TEAM_NAME

  let handleSubmit = async (event) => {
    event.preventDefault();


    const { stripe, elements } = props;
    if (!stripe || !elements) {
      return;
    }

    const card = elements.getElement(CardElement);
    let tokenId
    const result = await stripe.createToken(card);
    if (result.error) {
    } else {
      tokenId = result.token.id
    }

    
    const stripePromise = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY);
    const Checkout = () => {
      const {bodyAdquire} = useAppContext()
      return (
        <div className={Styles.App}>
          <div className={Styles.product}>
            <div>
              <Elements stripe={stripePromise}>
                <CheckoutForm tokens={bodyAdquire.tokens}/>
              </Elements>
            </div>
          </div>
        </div>
      );
    };

I solved it by removing the components that were not part of the page and leaving only the index file inside the next page.我通过删除不属于页面的组件并仅在下一页中保留索引文件来解决它。 Make sure to move any non-pages out of the pages folder.确保将所有非页面移出页面文件夹。

暂无
暂无

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

相关问题 Next.js i18n翻译URL出现404错误? - Next.js i18n translate URL occurs 404 error? 构建 Next.JS 和 tailwindcss - Build Next.JS and tailwindcss 第二次加载后加载文档页面 next.js vercel 应用程序时出现 500 错误 - Getting 500 error when loading document page next.js vercel app after second load 在 Next.JS 的 `getStaticPaths` 中设置 `fallback: true` 时,`throw new Error('Failed to load static props')` - `throw new Error('Failed to load static props')` when setting `fallback: true` in `getStaticPaths` in Next.JS 为什么我在 getInitialProps 中使用 params 在 Next.js 中构建时它们是未定义的 - Why I use params in getInitialProps they are undefined when build in Next.js Next.js 在内容为动态时尝试静态构建站点 - Next.js tries to build the site staticly when content is dynamic 带有Sass的Next.js发生错误,提示“您可能需要适当的加载程序来处理此文件类型错误” - Next.js with Sass occurs on error saying “ You may need an appropriate loader to handle this file type error” 如何在 Next.JS 中使用 getServerSideProps 从条带 api 获取用户数据? - How can I get user data from the stripe api with getServerSideProps in Next.JS? 尝试在 Next.JS web 应用程序中上传文本/图像时出现运行时错误 - I have a run time error when trying to upload text/image in Next.JS web app 在生产中构建 Next.js static 网站时获取错误 - Fetch error when building Next.js static website in production
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM