Unable to test Cloudflare Page Function: [wrangler:err] Error: No response!

I have a simple static site to which I want to add a Page Function. So far, I've read the tutorials at these links to get a sense for how this works (I'm migrating from Netlify):

https://developers.cloudflare.com/pages/functions/get-started/
https://developers.cloudflare.com/pages/how-to/refactor-a-worker-to-pages-functions/
https://developers.cloudflare.com/pages/functions/typescript/
https://developers.cloudflare.com/pages/tutorials/build-an-api-with-pages-functions/

Here is what I did:

1. Installed wrangler (v3.72.2).
2. Created a functions/api/comments.ts file in my Pages project directory.

export function onRequestGet() {
  return Response.json('test', { status: 200 });
}


3. Created the following wrangler.toml file at the root of my Pages directory:

# Top-level configuration
name = "comments"
main = "./functions/api/comments.ts"
send_metrics = false
compatibility_date = "2022-07-12"
node_compat = true
workers_dev = false


4. Ran
wrangler dev
to start up the local server.

But when I navigate to localhost:8787 (either in my browser or via curl), I get [wrangler:err] Error: No response!

The only way I'm able to get my function to work is if I convert it to a proper worker with a default export containing a
fetch
function as shown here:

Are Page Functions deprecated? If not, does anyone know what I'm doing wrong?
image.png
Was this page helpful?