workers-sdk: ๐ BUG: Cloudflare pages not deploying functions
What version of Wrangler are you using?
2
What operating system are you using?
Cloudflare Pages
Describe the Bug
Wrangler is not detecting functions routes, when deploying with Cloudflare Pgaes from github repo.
output below, when โ/functions/api/contact.tsโ function file exists.
| 11:19:55.381 | ๐ง โwrangler pages <command>โ is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose |
|---|---|
| 11:19:55.389 | |
| 11:19:55.490 | [31mโ [41;31m[[41;97mERROR[41;31m][0m [1mNo routes found when building Functions directory: /opt/buildhome/repo/functions[0m |
| 11:19:55.491 | |
| 11:19:55.491 | |
| 11:19:55.491 | [32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m |
| 11:19:55.502 | Warning: Wrangler did not find routes when building functions. Skipping. |
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 1
- Comments: 22 (3 by maintainers)
Hi, sorry to jump on an old issue, but I had this same problem and came across a different solution. I thought it would be worth sharing for anyone else stumbling across this topic.
Rather than setting the envrionment variable, I added the following to my
nuxt.config.ts:Also, itโs important that you run
nuxt buildrather thannuxt generate. When you choose the Nuxt preset, it choosesnpm run generateas the default build command and/distas the output directory.After setting the build command to
yarn buildand the output directory to.output/publicand adding the config above, it built successfully and I could see the SSR activity thanks to the new real-time logs.Finally, Nitro seems to detect the deployment environment (see Zero-Config Providers doc), and select the right preset (in this case
cloudflare_pagesI presume). In the Nitro clouldflare.ts, we can see :The server directory
/functionsfolder is emptied before each Nitro prerender. I suppose that Nuxt 3/serverfolder should be used as source of functions folder but thereโs some issues.I fixed the problem by setting the environment variable
NITRO_PRESET=node-serverin CF settings.@luc122c
Unfortunately that does not help those of us that that DO NOT want SSR, but still want the Cloudflare functions. With is preset you should be able to do either a SPA or SSR.
nuxt buildis for SSR andnuxt generateis for static/SPA. Currently it will not create the Cloudflare functions if you usenuxt generate