Publish on Cloudflare Pages with unsupported language versions

Emmanuel Gautier / December 06, 2022

2 min read

It may happen that a version of Node is not supported yet by Cloudflare and will remain not supported for some weeks. That can happen even if it is a Long Term Support (LTS) version. As I write those lines, the latest NodeJS LTS version is not supported yet (lts/hydrogen 18.x). This situation can be painful when a framework drops older version support or if you can not wait for having new features from a newer version of the language. For example, the newer major version of Gatsby, Gatsby 5, dropped support for older Node versions including the older LTS versions. CLoudflare teams make some proposals about the next upgrades and the upgrade cycle on Github Page Build discussion page.

At this moment, you have no way to make Cloudflare runtime build your project with the newer version of Gatsby. Of course, if you can, it is better to wait that Cloudflare upgrades its runtime and support the more recent version of Node. But if you want to upgrade and get benefits from the newer version of Node without removing Cloudflare Pages deployment and without waiting for Cloudflare upgrade, you have a solution we will talk about in this article.

Cloudflare Pages offer a way to build static sites and serve them thanks to their CDN. But you can choose to use only the hosting and serving part, and build the static site or static app by yourself. We already described this solution when we described how to have a Monorepo with Cloudflare Pages. This solution is to build the project on GitHub Actions (or any other CI solution) and push the build to Cloudflare.

Here is an example:

name: Publish

on:
  push:
    branches:
      - main

jobs:
  publish:
    runs-on: ubuntu-latest

    permissions:
      contents: read
      deployments: write

    steps:
      - name: Checkout 🛎
        uses: actions/checkout@v3

      - name: Setup node env 🏗
        uses: actions/setup-node@v3
        with:
          node-version: lts/gallium
          cache: 'yarn'

      - name: Install dependencies 👨🏻‍💻
        run: yarn --frozen-lockfile --silent

      - name: Run build
        run: yarn build

      - name: Publish
        uses: cloudflare/pages-action@1
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          projectName: gatsby-website
          directory: ./public
          gitHubToken: ${{ secrets.GITHUB_TOKEN }}

Consulting

If you're seeking solutions to a problem or need expert advice, I'm here to help! Don't hesitate to book a call with me for a consulting session. Let's discuss your situation and find the best solution together.

Share this post
Follow the RSS feed