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
🌐
Prisma
prisma.io › home › fields & types › fields & types › fields & types
Fields & types | Prisma Documentation
Prisma.Decimal uses Decimal.js, see Decimal.js docs to learn more. The use of the Decimal field is not currently supported in MongoDB. BigInt fields are represented by the BigInt type (Node.js 10.4.0+ required).
🌐
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 - Prisma Client now returns real JavaScript BigInts for Prisma BigInt fields, but they aren’t directly serializable.
Discussions

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
BigInt vs number
I want to use JS number, but need int8 as db row type. To work with int8 I need to assign BigInt as Prisma type within schema.prisma, which then in turn kills compatibility with number. Can I speci... More on github.com
🌐 github.com
3
5
BigInt and Number - SQL Server
I have a doubt. In my project I use SQL SERVER, and I generate the mapping structure of database with prisma generate command. After that, all schemas are mapping and I really can see and use the m... More on github.com
🌐 github.com
2
1
Prisma returning a bigint for an int field via $queryRaw
Pretty sure I run into this issue when I try to use count() as well. You just need to type cast country_prefix in your raw query. pc.country_query::int More on reddit.com
🌐 r/nextjs
3
1
April 18, 2024
🌐
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!

🌐
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 - type DBUser = { id: bigint } export const addProfile = inngest.createFunction( { id: "function-id"}, { event: "event-id" }, async ({ event, step }) => { const user: DBUser = await step.run( "get-user", async (email: string) => prisma.users....
🌐
GitHub
github.com › prisma › prisma › discussions › 20004
BigInt and Number - SQL Server · prisma/prisma · Discussion #20004
In my project I use SQL SERVER, and I generate the mapping structure of database with prisma generate command. After that, all schemas are mapping and I really can see and use the models. But when I have a BigInt field the Typescript don't understood like a Number and throw many errors by not found data types.
Author   prisma
🌐
Reddit
reddit.com › r/nextjs › prisma returning a bigint for an int field via $queryraw
r/nextjs on Reddit: Prisma returning a bigint for an int field via $queryRaw
April 18, 2024 -

I am using prisma but have been using raw queries for a handful of my complex fetches while I migrate to using it fully. I'm running into an issue where, from a raw query, a field that is an Int in both my schema and database is returning as a bigint which is throwing an error when I try to serialize the result later on. The problematic field is country_prefix.

The schema model for the table that country is coming from:

model countries {

id             Int     (autoincrement()) .UnsignedInt

country_name   String .VarChar(256)

country_prefix Int    .UnsignedInt
...

The query:

const countries = await prisma.$queryRaw\`  
SELECT pc.country_prefix,  
ct.city_name,  
ct.city_prefix,

...

The object I'm getting back:

{

country_prefix: 54n,

city_name: 'Villa Mercedes',

city_prefix: '2657',

...

I have seen other people online running into this issue when executing a raw query with COUNT but I'm not using count at all, just some table joins where none of the tables have fields that use bigint. Interestingly I don't see the error when running the app via `npm run dev` but when I run a built version or deploy it to vercel it starts throwing the error. I am currently working around it by mapping the repsponse and casting the field to a number but that sucks and I'd like to know why it's happening.

If anyone has run into this before help would be much appreciated.

Find elsewhere
🌐
GitHub
github.com › prisma › prisma › issues › 24136
Raw query returning a bigint for an int field · Issue #24136 · prisma/prisma
May 9, 2024 - Bug description When using prisma.$queryRaw to query data, columns of the Int.Unsigned type in MySQL will be converted to and returned as the Bigint type. How to reproduce Table Structure & Example Data: CREATE TABLE `folder` ( `id` int ...
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 19860
Allow to map `db.Decimal(X, 0)` to JS `bigint` · Issue #19860 · prisma/prisma
June 20, 2023 - The workaround is to create a large Decimal... for example, for a 256-bit unsigned integer you would need to use Decimal @db.Decimal(78, 0). This solves the storage problem, but it's inconvenient because you need to convert between bigint and Prisma.Decimal in the code.
Author   prisma
🌐
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?
🌐
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
🌐
Answer Overflow
answeroverflow.com › m › 1417967030816079993
Casting Postgres BigInt as TS Number - Prisma
September 17, 2025 - Hi everyone! I'm using Prisma on my Nest JS application that connects to a Postgres Database. Some fields in this DB are all BIGINT, and Prisma returns them as JS's BigInt. I undertand that in some cases, TS Number may not be able to handle such large numbers as BigInt.
🌐
Velog
velog.io › @ehgks0000 › prisma-bigint-to-number
prisma bigint to number
July 14, 2022 - ... //const user = ... ; const updatedData = JSON.stringify(user, (key, value) => (typeof value === "bigint" ? value = Number(value.toString()) : value)); console.log("prisma updatedData :", JSON.parse(updatedData));
🌐
Readthedocs
prismadb.readthedocs.io › en › latest › data-types
Data Types - Prisma/DB Documentation
Skip to content · Data Types · MySQL · SQL Server · length values for SQL Server datatypes can also be defined as MAX · PostgreSQL
🌐
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