Skip to content

Make effect-schema bufferSchema browser-safe#5462

Open
marbemac wants to merge 1 commit intodrizzle-team:betafrom
marbemac:fix/effect-schema-buffer-browser
Open

Make effect-schema bufferSchema browser-safe#5462
marbemac wants to merge 1 commit intodrizzle-team:betafrom
marbemac:fix/effect-schema-buffer-browser

Conversation

@marbemac
Copy link
Contributor

@marbemac marbemac commented Mar 8, 2026

The new drizzle-orm/effect-schema package (added in beta.15) has the same browser compatibility issue that was previously fixed for drizzle-arktype in #4424.

In effect-schema/column.ts:

export const bufferSchema = S.instanceOf(Buffer) satisfies Schema<Buffer>;

S.instanceOf(Buffer) evaluates Buffer eagerly at module load time. In browser environments Buffer doesn't exist, so importing drizzle-orm/effect-schema crashes immediately — even if none of your tables use buffer columns.

Same class of issue as #4383. The other validator packages (zod, valibot) already avoid this because zod.custom() / v.custom() wrap the instanceof check in a callback. The arktype fix in #4424 did the same thing.

Fix

// before — eagerly evaluates Buffer at import time
export const bufferSchema = S.instanceOf(Buffer) satisfies Schema<Buffer>;

// after — Buffer is only referenced at validation time
export const bufferSchema: Schema<Buffer> = S.declare(
	(input: unknown): input is Buffer => input instanceof Buffer,
);

Uses S.declare with a type guard so Buffer is only referenced when the schema is actually used for validation, not at module load. Same runtime behavior, just deferred.

Signed-off-by: Marc MacLeod <marbemac+gh@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant