Bug description
When running tests with Vitest in jsdom environment, reading or writing Bytes fields fails with:
Expected a byte array in column 'value', got object: <content>
This happens because jsdom creates its own JavaScript realm with separate built-in classes. A Uint8Array created in jsdom's realm fails instanceof Uint8Array checks in Node's realm where @prisma/adapter-pg runs.
Severity
🔹 Minor: Unexpected behavior, but does not block development
Reproduction
https://github.com/adri1wald/prisma-jsdom-bytes-issue
- Create a Vitest config with
environment: 'jsdom'
- Use
@prisma/adapter-pg with a model containing a Bytes field
- Create/read a record with
Buffer.from('test') or new TextEncoder().encode('test')
- Observe the error
Expected vs. Actual Behavior
- Expected: Bytes fields work the same as in Node environment
- Actual: Fails with "Expected a byte array in column 'value', got object"
Frequency
Consistently reproducible
Does this occur in development or production?
Only in development (e.g., CLI tools, migrations, Prisma Studio)
Is this a regression?
Likely introduced with Prisma 7
Workaround
Add // @vitest-environment node directive to test files, or configure Vitest to use node environment for server tests
Prisma Schema & Queries
model ProjectContext {
id String @id @default(cuid())
value Bytes
// ...
}
await prisma.projectContext.create({
data: { value: Buffer.from('test content') }
})
Prisma Config
// Add your `prisma.config.ts`
Logs & Debug Info
Environment & Setup
OS: macOS
Database: PostgreSQL
Node.js version: 24.x
Test runner: Vitest 4.x with jsdom
Prisma Version
Bug description
When running tests with Vitest in
jsdomenvironment, reading or writingBytesfields fails with:This happens because jsdom creates its own JavaScript realm with separate built-in classes. A
Uint8Arraycreated in jsdom's realm failsinstanceof Uint8Arraychecks in Node's realm where@prisma/adapter-pgruns.Severity
🔹 Minor: Unexpected behavior, but does not block development
Reproduction
https://github.com/adri1wald/prisma-jsdom-bytes-issue
environment: 'jsdom'@prisma/adapter-pgwith a model containing aBytesfieldBuffer.from('test')ornew TextEncoder().encode('test')Expected vs. Actual Behavior
Frequency
Consistently reproducible
Does this occur in development or production?
Only in development (e.g., CLI tools, migrations, Prisma Studio)
Is this a regression?
Likely introduced with Prisma 7
Workaround
Add
// @vitest-environment nodedirective to test files, or configure Vitest to usenodeenvironment for server testsPrisma Schema & Queries
Prisma Config
// Add your `prisma.config.ts`Logs & Debug Info
Environment & Setup
OS: macOS
Database: PostgreSQL
Node.js version: 24.x
Test runner: Vitest 4.x with jsdom
Prisma Version