Error deploying Sanity.io with Github action

1 replies
Last updated: Feb 22, 2023
Another day, another call for help from me.I’m using the
Github action for Sanity.io to deploy using the example workflow, but receive the following error:
The `sanity` module is not installed in current project
Project-specific commands not available until you run `yarn install`
Running 'yarn install'
yarn install v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
error @ixda-services/ixda-web@1.0.0-alpha: The engine "node" is incompatible with this module. Expected version "^16". Got "14.21.3"
On local dev I run node v16, and it works well.
AI Update

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 version

Your 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.

Well, I dropped relying on the plugin alltogether, and got it working after changing my github action script to this:
name: Deploy Sanity
on:
  push:
    branches: [main]
jobs:
  sanity-deploy:
    runs-on: ubuntu-18.04
    name: Deploy Sanity
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Install dependencies
        run: yarn install
      - name: Deploy Sanity Studio
        run: |
          cd studio
          npx @sanity/cli deploy
        env:
          SANITY_AUTH_TOKEN: ${{ secrets.SANITY_AUTH_TOKEN }}

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.

Was this answer helpful?