Failed Pages deployment

Hi, I’m trying to deploy my astro SSR site to Pages, and it all seems to work, right up until the end where it says

Upload complete. Assets Published

It then hangs for a second errors out:

12:13:00.422 :sparkles: Compiled Worker successfully
12:13:00.474 Found _routes.json in output directory. Uploading.
12:13:00.489 Validating asset output directory
12:13:01.317 Deploying your site to Cloudflare’s global network…
12:13:05.076 Uploading… (44/44)
12:13:05.077 :sparkles: Success! Uploaded 0 files (44 already uploaded) (0.42 sec)
12:13:05.386 :sparkles: Upload complete!
12:13:08.669 Success: Assets published!
12:13:09.731 Error: Failed to publish your Function. Got error: Uncaught Error: No such module “chunks/prerender_BU2rOQkH.mjs”. imported from “renderers.mjs”

Anyone know where I should start? No idea how to debug this tbh :confused:

1 Like

For me, I think it was because one of the modules was too large.

I tried building with output: "server" which I could then see what of the chunks was over the size limit.

It was actually because "astro-icon" was including everything in the build, resulting in a large pages.index chunk. So instead just changed the settings for it to include only what was needed.

Hey Carl, thanks for the reply.

Nice, I’ll give that a shot, thanks (*edit: I can’t see anything large). Seems to fit from the astro discord, maybe I’ve a large file that’s being removed:

What’s happening is that Astro runs the bundler once for both prerendered and on-demand routes, and for many projects that added a lot of unnecessary data on the upload for the workers, easily breaking the 10MiB limit.
The cloudflare adapter then removes those parts that are not needed to avoid this problem. That error you are seeing is because it removed a file that is only used during prerendering, but failed to remove a reference to it, so the deploy fails with a missing file

Replicated it here if it’s of any interest: GitHub - NickWoodward/Sub1Test


I took a look at your example repository, and it doesn’t look like a size problem to me.

What I did do, was:

  1. astro.config.mjs: output: 'hybrid'output: 'server'
  2. Remove export const prerender = false; from emailEnquity.ts and enquiry.ts
  3. Did a wrangler pages deploy dist --project-name testing-proj (probably not required, just easier than setting up Git to deploy from)
  4. Can see that it deployed:

I wonder if partially the issue I had was also because I was trying to use prerender exports. In any case, it all worked server side for me.

Likely there’s something more going on here, which I have no clue. Though maybe this is enough to keep you moving for now :+1:

Hey Carl,

Thanks for that, much appreciated!

You’re right, that does allow me to upload :slight_smile: Bitter sweet though - it’s broken all images and my site design, which is kind of weird as removing images locally doesn’t break anything :confused:

*Edit: yeah, it’s definitely now not loading images


Hey Nick,

Oh, that’s a shame about the images. I guess you could try tinker with the @astrojs/cloudflare | Docs imageservice setting. Maybe try cloudflare? Not sure if that’s part of the free pricing though, as it’s no longer “static”?:

On both free and paid plans, requests to static assets are free and unlimited. A request is considered static when it does not invoke Functions. Refer to Functions invocation routes to learn more about when Functions are invoked.

Might be a tricky balance to get right. Though I think playing around with a mix of hybrid output, and prerender might get you to a solution.

Definitely frustrating that it’s quite difficult to debug though :pensive:

Yeah, weirdly I’ve got hybrid and prerender=false working on the basic astro template (which I also used for my non-working example) GitHub - NickWoodward/astro-test

Tbh I’m wary of jumping into all those problems with images etc if I can manage to get hybrid working right. I guess I’m now building carefully on top of this example!

1 Like

Hello mate - sorry to message again so quickly, but you’re one of one for people who’ve also experienced this or similar by the looks of things!

I’ve narrowed it down to 1 small commit: simplified header · NickWoodward/astro-test@4db6b6f · GitHub with it fails, without works fine. Am stumped :smiley:

So I’ve narrowed it down to the @astrojs/cloudflare:^10.2.4 package. 9.1.0 works. But again, lots of weird nonsense with images not loading…

*Removing the image service from the adapter seemed to work. Thank god.

Hi, have you made any progress with this? After many hours of debugging, trying different configurations, and waiting on builds. I’ve come up with nothing. It seems for static assets like [slug].png.ts the route handler isn’t being included in the vite bundle for some reason.