TypeError: Do not know how to serialize a BigInt
- Prisma version (
prisma -vornpx 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%20Studio.app/Contents/Resources/app.asar/dist/renderer/assets/index.js:1:216912) at bs (file:///Applications/Prisma%20Studio.app/Contents/Resources/app.asar/dist/renderer/assets/vendor.js:27:50128) at Ha (file:///Applications/Prisma%20Studio.app/Contents/Resources/app.asar/dist/renderer/assets/vendor.js:27:67591) at bl (file:///Applications/Prisma%20Studio.app/Contents/Resources/app.asar/dist/renderer/assets/vendor.js:27:105796) at gu (file:///Applications/Prisma%20Studio.app/Contents/Resources/app.asar/dist/renderer/assets/vendor.js:27:97229) at hu (file:///Applications/Prisma%20Studio.app/Contents/Resources/app.asar/dist/renderer/assets/vendor.js:27:97154) at iu (file:///Applications/Prisma%20Studio.app/Contents/Resources/app.asar/dist/renderer/assets/vendor.js:27:94183) at file:///Applications/Prisma%20Studio.app/Contents/Resources/app.asar/dist/renderer/assets/vendor.js:27:45779 at e.unstable_runWithPriority (file:///Applications/Prisma%20Studio.app/Contents/Resources/app.asar/dist/renderer/assets/vendor.js:18:3854)
Please add:
BigInt.prototype.toJSON = function () {return this.toString()}
Hey @kakserpom, this was fixed in Prisma 3.7.0. If you update your Prisma version (or your electron app), this error should go away. Let me know if that's not the case, and I'll reopen!
@madebysid
Hey, could you try out the latest Prisma CLI and let me know if this is fixed on there?
I haven't released a new version of the Electron app yet, but I will do that with the next release (this Tuesday). If you could confirm that this is fixed for you on the CLI, then it'll be fixed in the Electron app as well (they use the same code).
Let me know!
@madebysid I am still seeing this using the Prisma CLI on Prisma v3.8.0:
TypeError: Do not know how to serialize a BigInt at JSON.stringify (
) at new er (http://localhost:5555/assets/index.js:1:162604) at bs (http://localhost:5555/assets/vendor.js:27:50128) at Ha (http://localhost:5555/assets/vendor.js:27:67591) at bl (http://localhost:5555/assets/vendor.js:27:105796) at gu (http://localhost:5555/assets/vendor.js:27:97229) at hu (http://localhost:5555/assets/vendor.js:27:97154) at iu (http://localhost:5555/assets/vendor.js:27:94183) at http://localhost:5555/assets/vendor.js:27:45779 at e.unstable_runWithPriority (http://localhost:5555/assets/vendor.js:18:3854)
$ npx prisma -v Environment variables loaded from .env prisma : 3.8.0 @prisma/client : 3.8.0 Current platform : debian-openssl-1.1.x Query Engine (Node-API) : libquery-engine 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node) Migration Engine : migration-engine-cli 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x) Introspection Engine : introspection-core 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x) Format Binary : prisma-fmt 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x) Default Engines Hash : 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f Studio : 0.452.0
Hmm, I can't seem to reproduce this, what are you doing exactly that causes this?
Here's what I did:
- Used a schema with a BigInt field (in Postgres)
- Opened up Studio via the CLI
- Created a new record & updated an existing one
Yeah I'm doing something different - I see the bug when looking at a row's relations.
Schema:
model User {
id BigInt @id
posts Post[]
}
model Post {
id BigInt @default(autoincrement())
userID BigInt
user User @relation(fields: [userID], references: [id])
@@id([userID, id])
}
Steps:
npx prisma studio- Create a User row and save it
- Click the
0 Postcell:
Ah, I see it now as well, weird. It only seems to happen when the ID is a BigInt. Nevertheless, I'll look into this, thanks for the repro!
I ran into the same issue and created my own prisma studio launch script by using the studio-server. It almost works, but I now get a Value must be a valid BigInt error. So I guess simply adding the toJSON and fromJSON will not do the trick completely.
import { enginesVersion } from '@prisma/engines';
import { getSchemaPathAndPrint } from '@prisma/migrate';
import { StudioServer } from '@prisma/studio-server';
import { loadEnvFile } from '@prisma/sdk'
import path from 'path';
import { logger } from './shared/logger';
const packageJson = require('../package.json'); // eslint-disable-line @typescript-eslint/no-var-requires
const port = 5555;
const schemaPath = 'prisma/schema.prisma';
declare global
{
interface BigInt
{
toJSON: () => number;
fromJSON: () => BigInt;
}
}
// eslint-disable-next-line no-extend-native
BigInt.prototype.toJSON = function () {
const int = Number.parseInt(this.toString());
return int ?? this.toString();
};
// eslint-disable-next-line no-extend-native
BigInt.prototype.fromJSON = function () {
return BigInt(this);
};
const main = async (): Promise<void> => {
await loadEnvFile(schemaPath, true);
await getSchemaPathAndPrint();
const staticAssetDir = path.resolve(__dirname, '../node_modules/@prisma/studio/dist');
const studio = new StudioServer({
schemaPath,
port,
staticAssetDir,
versions: {
prisma: packageJson.version,
queryEngine: enginesVersion,
},
})
await studio.start();
}
main().then(() => {
const serverUrl = `http://localhost:${port}`;
logger.info(`Prisma Studio is up on ${serverUrl}`);
}).catch((err) => logger.error(err));
I think it would be awesome if you could open source prisma studio at some point.
Ah, I see it now as well, weird. It only seems to happen when the ID is a BigInt. Nevertheless, I'll look into this, thanks for the repro!
Not entirely true, consider this schema:
model Guild {
id BigInt @id
channel BigInt?
addThread Boolean @default(false)
addButtons Boolean @default(true)
addUpdateHistory Boolean @default(false)
useEmbed Boolean @default(true)
suggestions Suggestion[]
}
The studio is able to render them just fine:

However, this one schema does not:
model Suggestion {
id Int
guild Guild @relation(fields: [guildId], references: [id])
guildId BigInt
authorId BigInt
messageId BigInt
createdAt DateTime @default(now())
repliedAt DateTime?
archivedAt DateTime?
@@id([id, guildId])
}
And will result on a non-recoverable error:
Screenshot

A less hacky alternative to serialize bigints would be to use JSON.stringify's replacer argument. For example, this code is able to serialize BigInts just fine:
JSON.stringify({ id: 42n }, (key, value) => (typeof value === 'bigint' ? value.toString() : value));
Results on:
{"id":"42"}
Hey :wave:
Prisma ORM 7 introduces a brand new standalone Studio, built from the ground up to work everywhere, with or without Prisma ORM. Consequently, all "old Studio" issues are being closed as there won't be any further work on it. :mega:
The new Studio is also available in the Prisma VS Code extension and in the Prisma Console application. :electric_plug:
Help shape, improve and fix the new Studio with us in this repository by submitting bug reports and feature requests. :construction_worker: