Error deploying Sanity.io with Github action
Based on your error message, the issue is clear: your GitHub Action is running Node.js 14.21.3, but your project requires Node.js 16 (as specified in your package.json's engine field). Even though your local development environment uses Node 16, the GitHub Action workflow is defaulting to an older version.
The fix is to explicitly specify the Node.js version in your GitHub Actions workflow file using the setup-node action. Here's how to update your workflow:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16' # or '16.x' for latest 16.x versionYour complete workflow should look something like this:
name: Deploy Sanity Studio
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
cache: 'yarn' # Optional: caches yarn dependencies for faster builds
- name: Install dependencies
run: yarn install
- name: Deploy Studio
run: npx sanity deploy
env:
SANITY_AUTH_TOKEN: ${{ secrets.SANITY_AUTH_TOKEN }}The key addition is the setup-node step before running yarn install. This ensures the GitHub Action runner uses the same Node.js version as your local environment.
Note: If you're using the official Sanity GitHub Action, you can still use setup-node before calling that action. The Sanity action is primarily a wrapper around the CLI for specific commands like dataset exports, but you'll still want to control the Node version for the overall workflow.
If you need to use a newer Node version (Node 20+ is now required for Sanity Studio v4), you can update both your local environment and the workflow accordingly by changing the node-version to '20'. More details about GitHub Actions workflows for Sanity can be found in the official documentation.
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.