Workers do not Come with Cargo

For Workers & Pages, what is the name of the domain?

Invalid

What is the error message?

16:05:04.586 Running custom build: cargo install -q worker-build && worker-build --release 16:05:04.590 /bin/sh: 1: cargo: not found 16:05:04.591 16:05:04.650 ✘ [ERROR] Running custom build cargo install -q worker-build && worker-build --release failed. There are likely more logs from your build command above.

What is the issue or error you’re encountering

Cannot deploy my application to cloudflare

What steps have you taken to resolve the issue?

16:05:04.586 Running custom build: cargo install -q worker-build && worker-build --release
16:05:04.590 /bin/sh: 1: cargo: not found
16:05:04.591
16:05:04.650 ✘ [ERROR] Running custom build cargo install -q worker-build && worker-build --release failed. There are likely more logs from your build command above.

What are the steps to reproduce the issue?

Take the rust template and run it → check GitHub - cloudflare/workers-rs: Write Cloudflare Workers in 100% Rust via WebAssembly for the axum template.
All you need is to try and get your template to run as a Cloudflare worker… and you’ll get the above logs because cargo was not found.

How can ‘npx wrangler deploy’ work if its command to start is ‘cargo install -q worker-build && worker-build --release’? I don’t see how it can run successfully.

Found a workaround for this one. Not optimal, but still better than nothing. Essentially, I will save a version of my build in my repository so that Cloudflare does not build it for me. Yes, there is a chance for error, but at least it works.

1-Build your project locally. You can do the whole ‘npx wrangler deploy’ on your machine.

2-Next, go to the generated build folder (directly under your main directory). You will find a .gitignore file within this folder. Open the .gitignore file, and remove the ‘*’ from its contents. This will make the files that have been built visible in your Github repository.

3-Once that is done, go to the wrangler.toml file and put nothing in the command entry. That is because Cloudflare does not allow you to set an empty string as your ‘Build Settings’ → Deploy Command. I found a way for it to do nothing by setting the wrangler.toml command empty.

That would make it:
[build]
command = “”

4- The last step is to push those changes to your repository.

To conclude, here are all the changes:

  • Remove the ‘*’ character from the .gitignore file in the generated ‘build’ folder to include all build files
  • Change the command entry to an empty string

And there you go! You now have a worker project that is active on Cloudflare :slight_smile: