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.
3. Created the following wrangler.toml
file at the root of my Pages directory:
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?5 Replies
Full stack trace (sorry, too long to post as plaintext)
I also get this warning in my server console when following the quickstart example
You should be using
wrangler pages dev
if you want to use Functions
You’re trying to load a single function as an entire worker right now, and that doesn’t work
Pages automatically bundles your functions into a worker. Simply run wrangler pages dev public
with your functions
next to your public dir, and where public
is a folder of static assets like HTMLAh, thanks James! Let me give that a shot.
Okay, that resolved my issue (I'm running into other unrelated errors now, but this has unblocked me). Thanks so much!
Happy to help!