This error occurs when Prisma Pulse attempts to serialize database change events but encounters unsupported data types or circular references. It prevents real-time notifications from being transmitted to subscribers.
The P6002 error indicates that Prisma Pulse is unable to serialize data from a database change event into a format suitable for transmission over the network. Prisma Pulse captures database changes and converts them into JSON-serializable events that subscribers receive. When the ORM encounters data types that cannot be serialized to JSON—such as BigInt, Decimal, Date objects, or circular references—it throws this P6002 error. This typically occurs when your database schema contains columns with types that JavaScript cannot natively serialize to JSON without special handling. The subscription fails because the change event cannot be transmitted to your application, breaking the real-time update pipeline. Understanding which data types are supported and how to handle them is essential for working with Prisma Pulse.
Enable Prisma query logging to identify which specific column is causing the serialization failure.
const prisma = new PrismaClient({
log: [
{ level: 'query', emit: 'event' },
{ level: 'error', emit: 'stdout' },
],
});
prisma.$on('query', (e) => {
console.log('Query: ' + e.query);
console.log('Duration: ' + e.duration + 'ms');
});Check your Prisma schema for BigInt, Decimal, Bytes, or nested Date fields in tables you're subscribing to.
If your schema uses BigInt (common for IDs in large systems), Prisma Pulse cannot serialize them directly. Convert to String in the subscription response.
Schema:
model User {
id BigInt @id @default(autoincrement())
email String @unique
score BigInt
createdAt DateTime @default(now())
}Subscribe with transformation:
const subscription = await prisma.user.subscribe({
create: { after: true },
});
for await (const event of subscription) {
// Manually convert BigInt to String for transmission
const data = {
...event.after,
id: event.after?.id?.toString(),
score: event.after?.score?.toString(),
};
console.log('User change:', data);
}This ensures BigInt values are converted to strings before they reach the serialization layer.
Prisma Decimal type is not natively JSON serializable. Use custom serialization in subscriptions.
Schema:
import Decimal from '@prisma/client/runtime/library';
model Product {
id String @id @default(cuid())
name String
price Decimal @db.Decimal(10, 2)
}Handle in subscription:
const subscription = await prisma.product.subscribe({
create: { after: true },
update: { after: true }
});
for await (const event of subscription) {
// Convert Decimal to string for serialization
const serializedData = {
...event.after,
price: event.after?.price?.toString(),
};
console.log('Product change:', serializedData);
}Always convert Decimal to string before sending over the network or storing in JSON fields.
If certain columns consistently cause serialization issues, exclude them from the subscription or filter them out after receiving the event.
// Instead of subscribing to entire record, subscribe to specific fields
const subscription = await prisma.user.subscribe({
create: {
after: true,
// Pulse doesn't support field-level filtering yet, so filter in application
}
});
for await (const event of subscription) {
// Filter out problematic fields before processing
const { problematicBigIntField, complexJSON, ...cleanData } = event.after || {};
// Process only serializable data
console.log('Clean data:', cleanData);
// Handle excluded fields separately if needed
if (problematicBigIntField) {
console.log('BigInt field:', problematicBigIntField.toString());
}
}This prevents the serialization error by removing problematic columns from the change event before they reach the network layer.
The best long-term solution is to modify your schema to use only JSON-serializable types where possible, especially for frequently-changing columns.
// ❌ Problematic types
model BadExample {
id BigInt @id // Not serializable
price Decimal @db.Decimal(10, 2) // Not serializable
data Bytes // Not serializable
updated DateTime // Tricky to serialize
}
// ✅ JSON-serializable alternatives
model GoodExample {
id String @id @default(cuid()) // String is always safe
price String @db.VarChar(20) // String representation
data String // Base64 or hex encoded
updated Int // Unix timestamp (number)
createdAt String @db.DateTime // ISO string if needed separately
}For new projects, use String IDs and represent numbers as strings or integers instead of specialized types.
Serialization Deep Dive:
Prisma Pulse uses native JavaScript serialization, which only supports:
- string
- number (not BigInt)
- boolean
- null
- object (plain objects and arrays)
- undefined (in non-JSON contexts)
Prisma-specific types that cause P6002:
- BigInt: Use .toString() or change schema to String with @db.VarChar
- Decimal: Always convert to string via .toString()
- Date: Convert to ISO string via .toISOString()
- Bytes: Convert to hex or base64 string representation
- Symbol: Not serializable, remove from subscription payloads
Custom Serialization Handler:
Create a utility to safely serialize Pulse events:
function serializeForPulse(data: any): any {
if (!data) return data;
if (typeof data === 'bigint') {
return data.toString();
}
if (data instanceof Decimal) {
return data.toString();
}
if (data instanceof Date) {
return data.toISOString();
}
if (Buffer.isBuffer(data)) {
return data.toString('hex');
}
if (Array.isArray(data)) {
return data.map(item => serializeForPulse(item));
}
if (typeof data === 'object') {
return Object.entries(data).reduce((acc, [key, value]) => {
acc[key] = serializeForPulse(value);
return acc;
}, {} as Record<string, any>);
}
return data;
}
const subscription = await prisma.user.subscribe({
create: { after: true }
});
for await (const event of subscription) {
const serialized = serializeForPulse(event.after);
// Now safe to send over the network or store
console.log('Serialized:', serialized);
}Testing for Serialization Issues:
Before deploying to production, test that all your subscription payloads can be serialized:
async function testSubscriptionSerialization() {
const testEvent = {
after: await prisma.user.findFirst()
};
try {
JSON.stringify(testEvent);
console.log('✓ Event is serializable');
} catch (error) {
console.error('✗ Event contains non-serializable types:', error);
// Fix the schema or add transformation logic
}
}Prisma Pulse Type Support Roadmap:
At the time of this writing, Prisma Pulse does not have special handling for BigInt, Decimal, or Bytes. The Prisma team has acknowledged these limitations. Monitor the [Prisma releases](https://github.com/prisma/prisma/releases) for built-in serialization helpers, which may eliminate the need for manual transformation in future versions.
In the meantime, always apply serialization transformations at the point of subscription to ensure reliable real-time updates.
P1013: The provided database string is invalid
The provided database string is invalid
P1000: Authentication failed against database server
Authentication failed against database server
P1010: User was denied access on the database
How to fix "P1010: User was denied access on the database" in Prisma
P5008: Usage exceeded, upgrade your plan (Accelerate)
How to fix "Usage exceeded, upgrade your plan" in Prisma Accelerate
P3021: Foreign keys cannot be created on this database
How to fix 'P3021: Foreign keys cannot be created on this database' in Prisma