Fix Cloudflare Pages deploy errors

Since discovering the wonders of Cloudflare Pages, I have shifted most of my static NuxtJS sites with Cloudflare Pages.

But with them still being the new kid on the block, I have run into a few random errors while deploying with Cloudflare Pages.

TLDR;

If you are having build errors with Cloudflare Pages, try these fixes:

  • ensure your packages are up to date
  • build Cloudflare Pages with a newer version of Node

Update Node version for Cloudflare Pages

Sometimes when using features only available in newer versions of Node or NPM, you might see errors like "ExperimentalWarning":

ERROR  (node:1569) ExperimentalWarning: The ESM module loader is experimental.

At the time of me writing this article, Cloudflare Pages uses v12.18.0 of Node, with v16 already out in the wild. So they are a bit behind.

Manually set Node version for Cloudflare Pages

To manually set the Node version for your Cloudflare Pages build, create an Environment variable for NODE_VERSION in both your production and preview deployments.

manually set the Node version for Cloudflare Pages

You can read more about the assorted build configurations in the official docs.


Building in public, sharing as I go →

You can find more details about my newsletter here.

PS: You can also follow on Twitter - @nickfrosty