Can`t use postgres-js in Cloudflare Pages

I am using hono + vite + postgresjs client
No description
6 Replies
Júlio
JúlioOP7mo ago
As I understand the package: https://github.com/porsager/postgres is compatible with cloudflare pages and I wouldn't have to use nodejs compat. And even if I do it does not work
GitHub
GitHub - porsager/postgres: Postgres.js - The Fastest full featured...
Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare - porsager/postgres
Júlio
JúlioOP7mo ago
The code:
import { Hono } from "hono";
import { renderer } from "./renderer";
import postgres from "postgres";

const app = new Hono();

app.use(renderer);

app.get("/", (c) => {
return c.render(<h1>Hello júlio!</h1>);
});

const sql = postgres(import.meta.env.VITE_DATABASE_URL, {
prepare: false,
});

app.get("/listings", async (c) => {
const listings = await sql`select * from listings limit 10;`;

return c.render(<pre>{JSON.stringify(listings, null, 2)}</pre>);
});

app.get("/projects/:name", (c) => {
return c.render(<h1>project {c.req.param("name")}</h1>);
});

export default app;
import { Hono } from "hono";
import { renderer } from "./renderer";
import postgres from "postgres";

const app = new Hono();

app.use(renderer);

app.get("/", (c) => {
return c.render(<h1>Hello júlio!</h1>);
});

const sql = postgres(import.meta.env.VITE_DATABASE_URL, {
prepare: false,
});

app.get("/listings", async (c) => {
const listings = await sql`select * from listings limit 10;`;

return c.render(<pre>{JSON.stringify(listings, null, 2)}</pre>);
});

app.get("/projects/:name", (c) => {
return c.render(<h1>project {c.req.param("name")}</h1>);
});

export default app;
kian
kian7mo ago
Are you sure those errors are coming from Postgres.js's code, i.e it goes away if you stop importing it?
Júlio
JúlioOP7mo ago
Yeah, removing it works fine
Júlio
JúlioOP7mo ago
GitHub
GitHub - juliomuhlbauer/hono-pages at postgresjs
Contribute to juliomuhlbauer/hono-pages development by creating an account on GitHub.
Júlio
JúlioOP5mo ago
It does not work with cloudflare workers either I could get working with worker with node_compat = true, but the pages does not accept this config I tried everything, don't know what do anymore Is a postgres.js or cloudflare problem? Issue unsolved Is there someplace that I can file an issue/ticket for this? This is stopping me moving to cloudflare
Want results from more Discord servers?
Add your server