It worked for me. Add this code to the beginning of yours.

BigInt.prototype.toJSON = function () {
  const int = Number.parseInt(this.toString());
  return int ?? this.toString();
};
Answer from Alirezakvr on Stack Overflow
🌐
GitHub
github.com › prisma › studio › issues › 614
Prisma Studio or Data Browser: `Do not know how to serialize a BigInt` · Issue #614 · prisma/studio
January 21, 2021 - Prisma Studio or Data Browser: Do not know how to serialize a BigInt#614 · Copy link · Labels · bug/2-confirmedBug has been reproduced and confirmed.Bug has been reproduced and confirmed.kind/bugA reported bug.A reported bug.old studiotopic: BigInttopic: Do not know how to serialize a BigInt ·
Author   prisma
Discussions

ERROR [ExceptionsHandler] Do not know how to serialize a BigInt
Bug description Hello Prisma Team, I cannot read a Bigint from a table in SQL Server. I had the following error: [Nest] 3312 - 2023-03-30, 1:35:29 p.m. LOG [NestApplication] Nest application succes... More on github.com
🌐 github.com
3
2
March 30, 2023
How to handle serialization in Prisma (TypeError: Do not know how to serialize a BigInt)
Hi everyone 👋 I’m encountering an issue when making a query in my app. The request fails with the following error: TypeError: Do not know how to serialize a BigInt After digging in, it seems that some values in my Prisma response include BigInt, which causes JSON.stringify() to fail. More on answeroverflow.com
🌐 answeroverflow.com
May 26, 2025
Prisma, Mysql and BigInts oh my
Big code smell here. Also why are you turning it into a string and then calling Number.parseInt()? Can you just call Number(this)? More on reddit.com
🌐 r/Nuxt
19
4
May 19, 2024
Prisma, Express, CockroachDB - Serialize BigInt Error when making POST request

You're seeing this because an Integer in CockroachDB is by default is an INT8 which is a 64-bit signed integers. It's represented in Javascript as a BigInt instead of a Number. You can get around this by doing an Int4 type in your schema file which will allow it to work as a regular JavaScript number.

For your case, you are using an auto-incrementing Int as the primary key. Better practice for CockroachDB is to use a UUID. CockroachDB also has a function to create this UUID for you. I suggest doing the following with your User model.

model User {
    id String default(dbgenerated("gen_random_uuid()")) db.Uuid
    email String name String?
}

I hope this helps.

More on reddit.com
🌐 r/node
3
2
October 27, 2022
🌐
Prisma
prisma.io › home › fields & types › fields & types › fields & types
Fields & types | Prisma Documentation
If you attempt to use JSON.stringify on an object that includes a BigInt field, you will see the following error: Do not know how to serialize a BigInt · To work around this issue, use a customized implementation of JSON.stringify: JSON.stringify( ...
🌐
Medium
medium.com › @truongtronghai › bigint-prisma-client-and-json-stringify-b5baa569cb47
BigInt, Prisma Client, and JSON.stringify | by Truong Trong Hai | Medium
September 5, 2024 - BigInt.prototype.toJSON = function () { return this.toString(); // Convert to string for serialization }; This way, when you stringify an object with BigInt properties, it’ll work as expected.
🌐
Answer Overflow
answeroverflow.com › m › 1376491369404563457
How to handle serialization in Prisma (TypeError: Do not know how to serialize a BigInt) - Prisma
May 26, 2025 - I've implemented the following serializer in order to conver these values from BigInt into string: // Custom JSON serializer to handle BigInt values const customJsonSerializer = (data: any) => { return JSON.stringify(data, (_, value) => typeof value === "bigint" ? value.toString() : value ); }; However, I wonder: Is there anything built into Prisma (or recommended by the team) to help convert BigInt into a JSON-safe format like string?
🌐
Reddit
reddit.com › r/nuxt › prisma, mysql and bigints oh my
r/Nuxt on Reddit: Prisma, Mysql and BigInts oh my
May 19, 2024 -

So I wanted to share my journey with everyone and shine some light on a weird problem that is probably common but doesn't seem to be discussed much.

I am in the process of rewriting a large 15-year old PHP/jQuery/MySQL app in Nuxt. One of my goals is to support my largeish (60 tables) legacy MySQL database. I was really looking forward to leveraging Nuxt's API and directory magic to modernize my old app!

I had used mysql2 successfully in a Vue 3 project I built this past winter and wanted to use it in Nuxt. Turns out there wasn't a documented way to do so. So I set about figuring out a way to wire it up into Nitro myself. I documented my findings here but I wasn't really happy as my solution wasn't the "preferred" way to do things. Pooya says we should not be attaching things to the nitroApp instance.

Time passed and I started playing with Prisma as it has direct support for MySQL and Nuxt. I figured I needed to wade into learning Prisma anyway. It is pretty cool but seems unnecessary since I already know how to write good SQL. The code hints are nice I guess but I digress...

I managed to get Prisma to "npx prisma db pull" my database schema (even on an older MySQL 5.7 setup) and start querying data. That was quick and easy. I was impressed!

But I immediately ran into a problem with BigInt. It seems even though I had no columns defined as BigInts I was getting the error: "Do not know how to serialize a BigInt". Turns out the reason for this is that my Int() columns are unsigned (I wanted to double the potential number of max id's for my tables) and this causes Prisma to *think* the data is a BigInt even though the maximum number of records in any of my tables is less than 10,000. Strange behavior indeed.

On a side note, the npmjs mysql2 package has a way to specify that you want the package to return BigInts as a string since JSON is the one choking on them. I couldn't find a way to tell Prisma to do this.

What I have done to circumvent the issue for now is to force Prisma to return what it perceives as BigInts as a string value, which is fine for my purposes.

I added the following code to the top of the defineEventHandler() function call in my /server/api/{endpoint} file:

    BigInt.prototype.toJSON = function () {
    const int = Number.parseInt(this.toString());
    return int ?? this.toString();
};

Now I am able to call prisma functions as normal and return the results. Now I can set my auto-increment record id's to BigInts as much as I want. Happy me!

The drawback to this approach is that I will have to add this code to every endpoint I write in my app. I am sure I will discover a way to have Prisma execute this code during instantiation but I haven't found a way to do it yet.

So I just wanted to share my story for folks who may be beating the crap out of Google/DuckDuckGo looking for a solution to this issue.

Thanks and cheers!

Find elsewhere
🌐
Reddit
reddit.com › r/node › prisma, express, cockroachdb - serialize bigint error when making post request
r/node on Reddit: Prisma, Express, CockroachDB - Serialize BigInt Error when making POST request
October 27, 2022 -

Hi All,

im trying to get the hang of using a CockroachDB and Prisma as an ORM. Im using express/js as my backend language.

When im attempting to make a Post request i get this error:

TypeError: Do not know how to serialize a BigInt

i found this solutions but have no idea how to apply it or where to use in my code.

./prisma/schema.prisma

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "cockroachdb"
  url      = env("DATABASE_URL")
}

model User {
  id    BigInt  @id @default(autoincrement())
  email String
  name  String?
}

---

./index.js

const express = require('express')
const { PrismaClient } = require('@prisma/client')
var cors = require('cors')

const prisma = new PrismaClient()
const app = express()

app.use(express.json())
app.use(cors())

app.post(`/signup`, async (req, res, next) => {
  try {
     const result = await prisma.user.create({
      data: {
        name: req.body.name,
        email: req.body.email
      },
    })

    res.json(result)
  } catch (error) {
    next(error)
  }
})

app.listen(3000, () => {
  console.log(`Example app listening on port 3000`)
})

Help would be appreciated thanks

🌐
GitHub
github.com › prisma › studio › issues › 756
TypeError: Do not know how to serialize `BigInt` · Issue #756 · prisma/studio
July 31, 2021 - model TournamentPrize { id BigInt @id @default(autoincrement()) createdAt DateTime @default(now()) @map(name: "created_at") @db.Timestamp(6) updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(6) customTypeId BigInt? @map(name: "custom_type_id") customType TournamentCustomPrizeType?
Author   prisma
🌐
GitHub
github.com › prisma › prisma › discussions › 5737
Postgresql TypeError: Do not know how to serialize a BigInt · prisma/prisma · Discussion #5737
March 15, 2022 - It seems you are on an older version of Prisma. I would suggest installing the latest version of Prisma 2.17.0 and then trying again. ... This will install the latest version and I tried that on a sample model which works fine with BigInt.
Author   prisma
🌐
Answer Overflow
answeroverflow.com › m › 1030578232346558586
Returning Prisma generated in nextjs issues error 'TypeError Do not know how to serialize a BigInt' - Theo's Typesafe Cult
November 1, 2022 - I tried following the thread here https://github.com/prisma/studio/issues/614 and it sounds like I have to monkeypatch BigInt to get it to work. Is there a better way? ... Prisma Studio or Data Browser: `Do not know how to serialize a BigI...
🌐
GitHub
github.com › prisma › prisma › issues › 5823
Do not know how to serialize a BigInt in executeRaw · Issue #5823 · prisma/prisma
February 24, 2021 - bug/2-confirmedBug has been reproduced and confirmed.Bug has been reproduced and confirmed.kind/bugA reported bug.A reported bug.topic: BigIntscalar type `BigInt`scalar type `BigInt` ... prisma.$executeRaw(`select my_custom_function(${foo_id.toString()}, ${bar_id.toString()}, ${woo_id.toString()})`);
Author   prisma
🌐
GitHub
github.com › prisma › prisma › discussions › 23189
Do not know how to serialize a BigInt Next14 · prisma/prisma · Discussion #23189
const updateRecipe = async (order: Order | undefined): Promise<any> => { //Serializa el BigInt a String ya que stringify no puede manejar bigints (BigInt.prototype as any).toJSON = function () { return this.toString(); }; try { const response = await fetch(`/api/orders/update`, { method: "POST", body: JSON.stringify(order), }); if (response.status === 200) { return await response.json(); } else { throw new Error(); } } catch (error) { return error; } }; ... import { prisma } from "@/lib/prisma"; async function POST(req: Request) { const body = await req.json(); const formattedDrugs = body.drugs.map((drug: string) => BigInt(drug)); try { const updatedRecipe = await prisma.orders.update({ where: { id: body.id, }, data: { givenAt: new Date( body.givenAt.replace(/(\d{2})-(\d{2})-(\d{4})/, "$3-$2-$1") ), retiredAt: body.retiredAt === null || body.retiredAt === "" ?
Author   prisma
🌐
GitHub
github.com › prisma › studio › issues › 816
TypeError: Do not know how to serialize a BigInt · Issue #816 · prisma/studio
December 26, 2021 - Prisma version (prisma -v or npx prisma -v): 3.6.0 Logs from Developer Tools Console or Command line, if any: TypeError: Do not know how to serialize a BigInt at JSON.stringify () at new Tl (file:///Applications/Prisma Studio.app/Conte...
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 22736
Do not know how to serialize a BigInt Next14 · Issue #22736 · prisma/prisma
January 21, 2024 - const updateRecipe = async (order: Order | undefined): Promise<any> => { //Serializa el BigInt a String ya que stringify no puede manejar bigints (BigInt.prototype as any).toJSON = function () { return this.toString(); }; try { const response = await fetch(`/api/orders/update`, { method: "POST", body: JSON.stringify(order), }); if (response.status === 200) { return await response.json(); } else { throw new Error(); } } catch (error) { return error; } }; ... import { prisma } from "@/lib/prisma"; async function POST(req: Request) { const body = await req.json(); const formattedDrugs = body.drugs.map((drug: string) => BigInt(drug)); try { const updatedRecipe = await prisma.orders.update({ where: { id: body.id, }, data: { givenAt: new Date( body.givenAt.replace(/(\d{2})-(\d{2})-(\d{4})/, "$3-$2-$1") ), retiredAt: body.retiredAt === null || body.retiredAt === "" ?
Author   prisma
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Errors › BigInt_not_serializable
TypeError: BigInt value can't be serialized in JSON - JavaScript | MDN
September 10, 2025 - You are trying to serialize a BigInt value using JSON.stringify, which does not support BigInt values by default. Sometimes, JSON stringification happens implicitly in libraries, as part of data serialization. For example, sending data to the server, storing it in external storage, or transferring it between threads would all require serialization, which is often done using JSON.
🌐
Medium
medium.com › @tbreijm › bigint-identifiers-when-using-prisma-and-inngest-with-js-ts-f78ac31e1e7a
BigInt identifiers when using Prisma and Inngest with TypeScript | by Tony Reijm | Medium
January 29, 2024 - Yeah so your user id isn’t serialised and therefore never returned as a result of your step call. That leaves you with one of the following options that revolve around the same thing use a toString and convert back with BigInt()