Error when running `sanity deploy` after upgrading project versions

8 replies
Last updated: Jun 17, 2024
Hey everyone! I just upgraded a project of mine from v2 and v3 and everything is working locally and the build is previewing locally as well. However, when I run
sanity deploy
, i'm getting the following error:
Error: sanity.cli.js does not contain a project identifier ("api.projectId"), which is required for the Sanity CLI to communicate with the Sanity API
Even though there is a
sanity.cli.js
in the root of the directory that looks like this:
import { defineCliConfig } from "sanity/cli"

export default defineCliConfig({
	api: {
		projectId: "my_project_id",
		dataset: "production",
	},
})
Anyone else hit this when upgrading? I also am getting a message in the terminal that I installed the nodes on the intel chip versus my m1 even though I've deleted my
node_modules
and re-run
npm i
. Don't know if they are connected. Thanks in advance for and help!
AI Update

This is a known issue that comes up after upgrading from Sanity v2 to v3! The problem is usually related to using an outdated global version of the Sanity CLI, even though your project configuration is correct.

Based on this community thread, the quickest solution is to run:

npx sanity deploy

This uses the latest version of the CLI without affecting your globally installed version. If that works (which it should), you can permanently fix the issue by updating your global CLI installation:

npm install --global sanity@latest

The issue occurs because older versions of the CLI (like 3.11.5 mentioned in the thread) don't properly read the new v3 configuration format in sanity.cli.js, even though the file is correctly structured. The CLI was updated to handle the ESM-based configuration files that Studio v3 uses.

Your sanity.cli.js file looks correct - it's using the proper defineCliConfig helper and has the required projectId and dataset fields. The problem is purely on the CLI side, not your configuration.

As for the Intel/M1 chip warning you're seeing - that's a separate issue related to npm installing binaries for the wrong architecture. It shouldn't affect the deploy error, but if you want to fix it, try:

rm -rf node_modules package-lock.json
npm install

One other thing to check: make sure your import statement in sanity.cli.js is exactly from "sanity/cli" (not /sanity/cli - note the leading slash). Some folks in the community thread mentioned that incorrect import path can also cause this error.

What version of the CLI is used when you run
sanity --version
?
Hey Geoff! Thanks for the response. I'm using 3.11.5
Could you please try running
npx sanity deploy
, which will ask to download and then use the latest version (without impacting the version you have installed)?
That seemed to do the trick, but did not ask to download anything. Thank you for your help!
Great! In that case, it’s possible there was a change in there somewhere, and upgrading your global install of the CLI (
npm i -g @sanity/cli
) should let you run
sanity deploy
without getting that error.
Thanks Geoff! Have a great day
You too! 🙌
Hey
user A
I'm experiencing this error at the moment.
I'm using
@sanity/cli version 3.16.7

sanity.cli.js file looks like this:

 /* eslint-disable no-process-env */
import { projectId, dataset } from './sanity.config.js'
import {defineCliConfig} from '/sanity/cli'

export default defineCliConfig({api: {projectId, dataset}})
And
npx sanity deploy
isn't quite doing the trick:
Error: sanity.cli.js does not contain a project identifier ("api.projectId"), which is required for the Sanity CLI to communicate with the Sanity API

Do you have any other ideas of how to debug this?
Thanks :)

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?