adminjs-prisma icon indicating copy to clipboard operation
adminjs-prisma copied to clipboard

TypeError: Do not know how to serialize a BigInt

Open capaj opened this issue 2 years ago • 4 comments

TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)
    at stringify (/home/capaj/work-repos/official/official-graphql/prisma-admin/node_modules/express/lib/response.js:1150:12)
    at ServerResponse.json (/home/capaj/work-repos/official/official-graphql/prisma-admin/node_modules/express/lib/response.js:271:14)
    at ServerResponse.send (/home/capaj/work-repos/official/official-graphql/prisma-admin/node_modules/express/lib/response.js:162:21)
    at handler (/home/capaj/work-repos/official/official-graphql/prisma-admin/node_modules/@adminjs/express/src/buildRouter.ts:60:15)

I got this in my schema:

  id               BigInt          @id @default(autoincrement())

capaj avatar Sep 11 '22 11:09 capaj

I think this is an issue with prisma itself and nothing to do with adminjs. https://github.com/prisma/studio/issues/816

monish96 avatar Dec 25 '22 15:12 monish96

facing the same issue

UdittLamba avatar Apr 19 '23 08:04 UdittLamba

ok, So I fixed it by patching the bigint prototype BigInt.prototype.toJSON = function () { const int = Number.parseInt(this.toString()) return int ?? this.toString() }

reference

UdittLamba avatar Apr 19 '23 08:04 UdittLamba

Yes we have the same hackfix In our own codebase. This should resolve it.

capaj avatar Apr 19 '23 09:04 capaj