Home / Blog / Eleventy on Cloudflare Workers: One wrangler.jsonc and the Build Errors I Hit

I spent a good part of this fall moving Eleventy sites off of netlify and mostly to xmit.co and I experimented with moving some sites to cloudflare worker sites including the podcast.lakeback.org site, and two of my theme experiments, wisp and brutalism. Some of them now run on Build Awesome, the new name for Eleventy 4, and some are still on @11ty/eleventy 3. The deployment is the same either way. Eleventy writes a folder of HTML, and Cloudflare serves that folder.

This post has two parts. The first is the wrangler.jsonc I now copy into every new project, explained line by line. The second is the build and deploy errors I hit along the way, with the fix for each, in roughly the order you would meet them. I did most of this work with Claude Code, and several of the explanations below started as its commit messages. I kept the ones I could check against the build logs.

domain names #

If you buy your domain names via cloudflare the pro is they are very cheap the con is you have to use cloudflare.

Pages or Workers? #

Cloudflare used to point static sites at Pages. For new projects it now points them at Workers with static assets. For a site with no server code, the difference you feel is the config file. Pages was set up in the dashboard. A Worker is described by a wrangler.jsonc in the repository, so the deployment is versioned alongside the site.

The wrangler.jsonc #

Here is the file from the podcast, with my comments left in. JSONC is JSON that allows comments, and I use them to write down why each line is there.

{
  // Must match the Workers Builds project name in the Cloudflare dashboard.
  "name": "podcast-lakeback-org",
  "compatibility_date": "2026-09-02",
  "assets": {
    "directory": "./_site",
    // Eleventy emits directory-style URLs (/entry/money/index.html) and every
    // internal link carries the trailing slash. Keep Cloudflare agreeing.
    "html_handling": "force-trailing-slash",
    "not_found_handling": "404-page"
  },
  "routes": [
    { "pattern": "podcast.lakeback.org", "custom_domain": true }
  ],
  // The custom domain is the only address.
  "workers_dev": false,
  "preview_urls": false
}

There is no main and no Worker script. Cloudflare's configuration docs list main as optional for an assets-only Worker. Line by line:

  • name is the Worker's name. If you connect the repo through Workers Builds, Cloudflare creates the project first and names it after the repository. Your name has to match that.
  • compatibility_date pins the runtime behaviour. For an assets-only site it barely matters, but wrangler wants it. Set it to the day you create the file.
  • assets.directory is Eleventy's output folder. _site is the default. Change it if your config sets dir.output. The podcast site writes to ./dist.
  • html_handling: "force-trailing-slash" matches the way Eleventy writes pages. A file at about/index.html is served at /about/, and a request for /about redirects there. The default, auto-trailing-slash, also serves folder indexes with a slash, but I would rather state the behaviour than inherit it.
  • not_found_handling: "404-page" serves the nearest 404.html with a 404 status. Make a 404.md with permalink: 404.html and you are done.
  • routes with custom_domain: true attaches the hostname as a Custom Domain, so you don't edit DNS yourself. This assumes the zone is already on your Cloudflare account.
  • workers_dev and preview_urls set to false turn off the *.workers.dev address and the version and preview URLs. More on why I write these out below.

Two optional files belong next to it: a .nvmrc with your Node major, and a _headers file that ends up at the root of _site. I keep mine in public/ and passthrough-copy it.

/*
  X-Content-Type-Options: nosniff
  Referrer-Policy: strict-origin-when-cross-origin

/dist/*
  Cache-Control: public, max-age=31536000, immutable

My first Cloudflare site, brutalism, had a worker.js that did nothing but hand every request to the ASSETS binding, plus a main line in the config pointing at it.

export default {
  async fetch(request, env) {
    return env.ASSETS.fetch(request);
  }
};

You don't need this. With no main, Cloudflare serves the assets directory directly. Delete the script and the main line.

Two ways to deploy #

From your own machine, build and then deploy:

npm run build && npx wrangler@4 deploy

The other way is Workers Builds, which runs on Cloudflare. In the dashboard, go to Workers & Pages, then Create, then Import a repository. Set the build command to npm run build and the deploy command to npx wrangler deploy. Every push to main then builds and deploys on Cloudflare's runner. Cloudflare also builds non-production branches, but with preview_urls: false I don't expect a preview URL from them, so I don't rely on previews.

I now use Workers Builds for everything. I also tried GitHub Actions with cloudflare/wrangler-action. Pick one. Two of the errors below come from having both.

The build errors #

The build ran on the wrong Node #

The wisp theme's builds on Cloudflare were failing because Corepack could not activate the pinned npm. package.json said "engines": { "node": ">=24" } and "packageManager": "[email protected]", but .nvmrc said 20. In those builds, Cloudflare's image followed .nvmrc rather than the NODE_VERSION variable, so the build ran on Node 20, and Corepack no longer supports Node 20. Changing .nvmrc to 24 fixed it. Keep the two in agreement.

Pagefind and the registry #

This one is a precaution. Nothing failed. Several of my sites run Pagefind after Eleventy finishes. Wisp calls it with npx --no-install pagefind, so the build uses the locked devDependency instead of reaching out to the npm registry from the build sandbox. If the local copy is missing, the build fails loudly rather than downloading whatever version is current.

"Missing entry-point" #

A deploy through GitHub Actions stopped with Missing entry-point. wrangler-action@v3 defaults to wrangler 3, which could not deploy an assets-only Worker because there was no main script for it to find. Wrangler 4 can.

On the action, set wranglerVersion: "4". Locally, call npx wrangler@4, because a bare npx wrangler resolves to whatever is latest, which may not be what CI pins. Better, add wrangler as a devDependency. The podcast's build log showed a cold npx wrangler install taking 11.6 seconds, and the devDependency removed that step.

The API token that passed whoami #

While I was still deploying from Actions, wrangler whoami worked and the deploy failed. A token without Workers Scripts: Edit passes whoami and fails only on deploy. Create the token from the Edit Cloudflare Workers template.

The name mismatch #

Cloudflare flagged a name mismatch on every build of the podcast. The name in wrangler.jsonc did not match the project. I had written podcast-lakeback, and Workers Builds had created podcast-lakeback-org, after the repo. The other repo is called podcast.lakeback.org, and Cloudflare derived podcast-lakeback-org from it. Watch the names carefully.

Cloudflare's Workers Builds docs say the dashboard name must match the config name and that a mismatch can fail the build. Mine only warned. I changed name to whatever the dashboard said rather than renaming the project.

Why I write out workers_dev and preview_urls #

Wrangler warned on every deploy that my local and dashboard config differed. I had left both keys unset. By the docs, an unset preview_urls leaves whatever the dashboard has, so the two can disagree. An unset workers_dev can also leave a second copy of the site reachable at *.workers.dev. Set both explicitly. If you want the workers.dev address, say true.

The 200 that meant nothing #

The podcast's domain returned 200 OK before anything of mine had deployed. It was serving Cloudflare's 11-byte "Hello world" placeholder, which sits on the route until the first real deploy replaces it. Look at the body, not the status. curl -s https://your.domain.com | head is enough.

Two deploys for every push #

The podcast was connected to Workers Builds and also had a GitHub Actions workflow running wrangler deploy, so every push deployed twice. I removed the Actions workflow.

Wisp had a quieter version of the same problem. It was still connected to an old Cloudflare Pages project of the same name, whose builds had been failing. Pages and Workers are separate products, so leaving both connected deploys the site twice. Disconnect the Pages project's Git integration, then remove its custom domain before you add the domain to the Worker. Cloudflare will not let two projects claim the same hostname.

What I copy into a new project #

  1. wrangler.jsonc as above, with name matching the project.
  2. .nvmrc matching engines.node.
  3. wrangler and pagefind as devDependencies.
  4. _headers in the passthrough folder.
  5. Any build-time secret under Build, then Variables and secrets.
  6. One deploy path.

Most of these errors had nothing to do with Eleventy. Eleventy did its job every time and wrote the folder. What broke was everything around it: which Node ran, which store held a secret, which of two systems got to deploy, and what name the dashboard had already picked. The config file is short. The dashboard holds the other half of the setup, and the two have to agree.

If you are moving an Eleventy site to Workers and hit an error that is not on this list, write to me. I would like to add it.

Tags : 11ty eleventy build-awesome cloudflare static-sites web-development

Webmentions

No webmentions yet.

Previous

Getting Started with Integrating CMS's into #11ty and #BuildAwesome

A sequel to the getting-started guide: what a Git-based CMS does for an 11ty (Build Awesome) site, working configs for Pages CMS and Decap CMS, the Git Gateway worry, a plan for moving to Sveltia CMS, and why 11tyCMS is the one to watch.