Skip to content

vesion 1.4 .* TypeError: midtrans_client__WEBPACK_IMPORTED_MODULE_0___default(...).Snap is not a constructor #75

@Novianto778

Description

@Novianto778

There is a bug when using midtrans-client in version 1.4 above
TypeError: midtrans_client__WEBPACK_IMPORTED_MODULE_0___default(...).Snap is not a constructor

env:
Next.js 14.2.5 (app router)
midtrans-client 1.4.0 and 1.4.1

code:

import Midtrans from "midtrans-client";

let snap = new Midtrans.Snap({
  isProduction: false,
  serverKey: process.env.NEXT_PUBLIC_MIDTRANS_SERVER_KEY,
  clientKey: process.env.NEXT_PUBLIC_MIDTRANS_CLIENT_KEY,
});

export async function POST(request: Request) {
  //   const body = await request.json();

  let parameter = {
    transaction_details: {
      order_id: "YOUR-ORDERID-123456",
      gross_amount: 10000,
    },

    customer_details: {
      first_name: "budi",
      last_name: "pratama",
      email: "budi.pra@example.com",
      phone: "08111222333",
    },
  };

  const res = await snap.createTransaction(parameter);

  return new Response(JSON.stringify(res), {
    headers: { "Content-Type": "application/json" },
  });
}

image

Solution: downgrade to 1.3.* version

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions