Fails with `Error: The script will never generate a response.` on cloudflare pages
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
Description
This is similar to #865, however unlike in that issue I create the postgres client on each request and still get following error on cloudflare pages with "compatibility_flags": ["nodejs_compat"]
✘ [ERROR] A hanging Promise was canceled. This happens when the worker runtime is waiting for a Promise from JavaScript to resolve, but has detected that the Promise cannot possibly ever resolve because all code and events related to the Promise's I/O context have already finished.
[wrangler:inf] GET /api/test 500 Internal Server Error (8ms)
✘ [ERROR] Uncaught (in response) Error: The script will never generate a response.
Using it as follows
app.get("/api/test", async (c) => {
console.log("test route");
const sql = postgres(c.env.DATABASE_URL);
const users = await sql`
select *
from users`;
// users = Result [{ name: "Walter", age: 80 }, { name: 'Murray', age: 68 }, ...]
return c.json(users);
});
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the /api/test route on Cloudflare Pages with the nodejs_compat compatibility flag, using the per-request postgres(c.env.DATABASE_URL) setup shown. Trace the query and response lifecycle; done means the route returns the users as JSON without the hanging-Promise or “never generate a response” errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js, postgresql
- Domain
- cloud, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100