[英]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.