github-action-sanity
github-action-sanity copied to clipboard
Error: sanity.cli.ts does not contain a project identifier
I am getting the error: "Error: sanity.cli.ts does not contain a project identifier ("api.projectId"), which is required for the Sanity CLI to communicate with the Sanity API"
To Reproduce
Steps to reproduce the behavior:
- Use the export/backup example code but use the latest version 0.7-alpha
- Used a read+write token since I was also going to use the sanity dataset import but never got to that point
- Received error
Expected behavior
The workflow should succeed
Screenshots
Which versions of Sanity are you using? v3.21.3
I think this is an issue with the latest sanity cli because when you use a js file instead of ts then it does work
In my case (and probably most of you too if you've followed Sanity's setup for NextJS), the issue is that I read these variables from the environment.
import { defineCliConfig } from "sanity/cli";
const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID;
const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET;
export default defineCliConfig({
api: { projectId, dataset },
});
Providing those in the env
of the workflow step fixed this specific issue.
- name: Export Dataset
uses: sanity-io/[email protected]
with:
args: dataset export [DATASET] [UPLOAD_FILE_PATH]
env:
SANITY_AUTH_TOKEN: [TOKEN]
NEXT_PUBLIC_SANITY_PROJECT_ID: [PROJECT_ID]
NEXT_PUBLIC_SANITY_DATASET: [DATASET]
Alternatively, you could also have a step that deletes the file and rewrites it with the values populated:
- run: |
rm sanity.cli.ts && echo 'export default { api: { projectId: "PROJECT_ID", dataset: "DATASET" } }' > sanity.cli.ts
However, I then got a new error, which has been reported here: https://github.com/sanity-io/github-action-sanity/issues/23 . The workaround suggested by this comment fixed the new error. This was my final configuration to make it work with the latest CLI (3.43.0):
- name: Export dataset
run: npx sanity dataset export ${{ inputs.dataset || 'production' }} ${{ steps.upload_name.outputs.UPLOAD_NAME }}
env:
SANITY_AUTH_TOKEN: ${{ secrets.SANITY_TOKEN }}
NEXT_PUBLIC_SANITY_PROJECT_ID: ${{ secrets.SANITY_PROJECT_ID }}
NEXT_PUBLIC_SANITY_DATASET: ${{ inputs.dataset || 'production' }}