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 โœ˜ [ERROR] No routes found when building Functions directory: /opt/buildhome/repo/functions
11:19:55.491
11:19:55.491
11:19:55.491 If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose
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)

Most upvoted comments

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:

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  nitro: {
    preset: "cloudflare_pages",
  },
});

Also, itโ€™s important that you run nuxt build rather than nuxt generate. When you choose the Nuxt preset, it chooses npm run generate as the default build command and /dist as the output directory.

After setting the build command to yarn build and the output directory to .output/public and 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_pages I presume). In the Nitro clouldflare.ts, we can see :

...
output: {
    serverDir: '{{ rootDir }}/functions'
},
...

The server directory /functions folder is emptied before each Nitro prerender. I suppose that Nuxt 3 /server folder 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-server in CF settings.

@luc122c

Also, itโ€™s important that you run nuxt build rather than nuxt generate. When you choose the Nuxt preset, it chooses npm run generate as the default build command and /dist as the output directory.

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 build is for SSR and nuxt generate is for static/SPA. Currently it will not create the Cloudflare functions if you use nuxt generate