Next.js Discord

Discord Forum

NextJS Server Action problem

Devon Rex posted this in #help-forum
Open in Discord
Devon RexOP
I am getting this error when submitting form from next client to next server.
Error: Failed to find Server Action "null". This request might be from an older or newer deployment. Original error: Invariant: Missing 'next-action' header.   

But I can't figure out what the main reason is.
Could anyone help me, please?
This is next client that sends post request.
import React from 'react';
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(
export default function PreviewPage() {
  return (
    <form action="/api/checkout_sessions" method="POST">
        <button type="submit" role="link">

This is next server code that receives post request.
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);

export default async function handler(req, res) {
  if (req.method === 'POST') {
    try {
      // Create Checkout Sessions from body params.
      const session = await stripe.checkout.sessions.create({
        line_items: [
            price: '{{PRICE_ID}}',
            quantity: 1,
        mode: 'payment',
        success_url: `${req.headers.origin}/?success=true`,
        cancel_url: `${req.headers.origin}/?canceled=true`,
      res.redirect(303, session.url);
    } catch (err) {
      res.status(err.statusCode || 500).json(err.message);
  } else {
    res.setHeader('Allow', 'POST');
    res.status(405).end('Method Not Allowed');

0 Replies