Skip to content

@prisma/adapter-pg Bytes field fails in jsdom environment due to cross-realm instanceof Uint8Array check #29129

Description

@adri1wald

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

  1. Create a Vitest config with environment: 'jsdom'
  2. Use @prisma/adapter-pg with a model containing a Bytes field
  3. Create/read a record with Buffer.from('test') or new TextEncoder().encode('test')
  4. 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

// Debug logs here

Environment & Setup

OS: macOS
Database: PostgreSQL
Node.js version: 24.x
Test runner: Vitest 4.x with jsdom

Prisma Version

7.3.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions