Deploy working, but Cloudflare build failing

I'm having a bit of a weird problem with https://github.com/jakearchibald/random-stuff. If I pnpm run build and pnpm run deploy, everything works fine. However, if I push to GitHub, the Cloudflare build fails with:
Error: The provided Wrangler config main field (/opt/buildhome/repo/dist/random_stuff/index.js) doesn't point to an existing file
Error: The provided Wrangler config main field (/opt/buildhome/repo/dist/random_stuff/index.js) doesn't point to an existing file
Am I holding it wrong? I'm trying to get wrangler to use the build version of the JS for the worker. If I don't manually point it there, it tries to use the unbuilt version.
5 Replies
Chaika
Chaika3mo ago
Am I holding it wrong?
Yes, the point of CI/CD is that you get it to build your app for you and then push the build version. You can set your build command in the setup under Settings -> build -> Build command, and then you can also set a deploy command. It's specifically erroring in this case because dist is part of your gitignore https://github.com/jakearchibald/random-stuff/commit/67f3755dded36982755a4c57f93df02c104b31b5, but you shouldn't be using the built version anyway
Jake Archibald
Jake ArchibaldOP3mo ago
Really? It's pretty unusual to have to push the built version to CI. I have my build command set, and I see it building in the logs ah, ok, it only worked locally due to a previous build. I can make it fail locally now
but you shouldn't be using the built version anyway
What should I be doing if I want to run my worker scripts through a build script?
Chaika
Chaika3mo ago
I mean you have the CI/CD build the app, and then deploy that freshly Built version. Unlike what you are doing now, which is targeting the dist and not building in ci/cd
Chaika
Chaika3mo ago
ahh ok, I see better now. you're using vite to try to build. I haven't played around with the integration of Wrangler and vite, but my understanding is you'd still want the main as defined in your wrangler config to be the unbundled code: https://developers.cloudflare.com/workers/vite-plugin/get-started/ I'd try pointing it back to your unbundled/src workers entrypoint, and then try building like that. There's a channel in here for the vite plugin as well #vite-plugin
Cloudflare Docs
Get started
Get started with the Vite plugin
Jake Archibald
Jake ArchibaldOP3mo ago
Thank you. I'll try in that channel. If I point wrangler at the unbuilt file, it tried to use it in production and fails. I feel like it's worked before, so something else is going on here. I'll ask in that other channel, thank you

Did you find this page helpful?