Skip to content

Commit 5dc5cfc

Browse files
authored
fix: replace npm:postgres with jsr:@oscar6echo/postgres for Supabase Edge Runtime compatibility (#552)
# Fix Supabase Edge Runtime compatibility with postgres client This PR replaces `npm:postgres` with `jsr:@oscar6echo/postgres` fork to fix compatibility issues with Supabase Edge Runtime. The original npm package fails to parse database URLs in Deno edge environments, causing CONNECT_TIMEOUT errors. ## Changes: - Replaced `npm:postgres@3.4.5` with `jsr:@oscar6echo/postgres@3.4.5-d` in all Deno configuration files - Updated type imports from `Sql` to `postgres.Sql` throughout the codebase - Added documentation in the README explaining why we're using a fork - Removed deno.lock files which will be regenerated with the new dependency The fork is functionally identical to postgres v3.4.5, with only the export syntax changed for Deno/JSR compatibility. This resolves the issue described in porsager/postgres#839.
1 parent afe9e85 commit 5dc5cfc

File tree

19 files changed

+71
-532
lines changed

19 files changed

+71
-532
lines changed

.changeset/jsr-postgres-fork.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@pgflow/edge-worker': patch
3+
'@pgflow/dsl': patch
4+
'pgflow': patch
5+
---
6+
7+
Fix Supabase Edge Runtime compatibility by replacing npm:postgres with jsr:@oscar6echo/postgres fork. The npm package fails to parse database URLs in Deno edge environments, causing CONNECT_TIMEOUT errors.

apps/demo/supabase/functions/article_flow_worker/deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"@pgflow/edge-worker": "../_vendor/@pgflow/edge-worker/index.ts",
99
"@pgflow/edge-worker/": "../_vendor/@pgflow/edge-worker/",
1010
"@pgflow/edge-worker/_internal": "../_vendor/@pgflow/edge-worker/_internal.ts",
11-
"postgres": "npm:postgres@3.4.5",
11+
"postgres": "jsr:@oscar6echo/postgres@3.4.5-d",
1212
"@henrygd/queue": "jsr:@henrygd/queue@^1.0.7",
1313
"@supabase/supabase-js": "jsr:@supabase/supabase-js@^2.49.4"
1414
}

apps/demo/supabase/functions/article_flow_worker/deno.lock

Lines changed: 0 additions & 46 deletions
This file was deleted.

pkgs/cli/supabase/functions/pgflow/deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"@pgflow/edge-worker/_internal": "../_vendor/@pgflow/edge-worker/_internal.ts",
1616
"@henrygd/queue": "jsr:@henrygd/queue@^1.0.7",
1717
"@supabase/supabase-js": "jsr:@supabase/supabase-js@^2.49.4",
18-
"postgres": "npm:postgres@3.4.5",
18+
"postgres": "jsr:@oscar6echo/postgres@3.4.5-d",
1919
"@std/crypto": "jsr:@std/crypto"
2020
}
2121
}

pkgs/dsl/src/platforms/supabase.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Sql } from 'postgres';
1+
import type postgres from 'postgres';
22
import type { SupabaseClient } from '@supabase/supabase-js';
33
import {
44
Flow as CoreFlow,
@@ -8,7 +8,7 @@ import {
88

99
/* ---------- 1. Resources ------------------------------------------- */
1010
export interface SupabaseResources extends Record<string, unknown> {
11-
sql : Sql;
11+
sql : postgres.Sql;
1212
/**
1313
* Supabase client with service role key for full database access
1414
*/

pkgs/edge-worker/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,16 @@ To run a manual test:
208208
1. Start Supabase: `pnpm nx supabase:start edge-worker`
209209
2. Follow the instructions in the specific test's README
210210

211+
## Dependencies
212+
213+
### PostgreSQL Client
214+
215+
This package uses `jsr:@oscar6echo/postgres` - a JSR-compatible fork of the popular [postgres](https://github.com/porsager/postgres) package.
216+
217+
**Why a fork?** The official `npm:postgres` package uses CommonJS exports (`export =`) which are incompatible with JSR's ES Module requirements. The npm version also fails to parse database URLs correctly in Supabase Edge Runtime, causing `CONNECT_TIMEOUT` errors. See [porsager/postgres#839](https://github.com/porsager/postgres/issues/839) for details.
218+
219+
The fork is functionally identical to postgres v3.4.5, with only the export syntax changed for Deno/JSR compatibility.
220+
211221
## Building
212222

213223
Run `nx build edge-worker` to build the library.

0 commit comments

Comments
 (0)