CLI errors
You may run into errors while using the CLI. Listed below are some explanations and common solutions for these errors.
Gotcha
Some error explanations may be missing. If you cannot find the error you are looking for, please use the feedback form to let us know or make a post in our Slack Community.
This error often occurs when you do not have the correct permission to install packages with npm
.
You can fix this by changing the owner of the global node_modules
folder using the following command:
sudo chown -R $USER /usr/local/lib/node_modules
Another option to fix this issue is managing your node version(s) with a version manager like nvm or asdf.
If you're using a Windows computer and running into an error that resembles the one above while attempting to install (or use) the Sanity CLI, it's likely that there is an issue with the $PATH
environment variable of your operating system.
To fix this, ensure the variable is correctly set before rerunning the CLI. More information on troubleshooting can be found in this thread on Stack Overflow.
This error often occurs when there is another process or service running on the Sanity studio's default port (3333).
To fix this, try stopping or closing other applications running on that port.
If you're on Mac, you can quickly kill the process running on port 3333 using the following command:
lsof -ti :3333 | xargs kill -9
If you'd instead like to change which process the Studio runs on, you can do so by passing an alternative value to the --port
option of the sanity start
and sanity preview
commands.
Just be sure to add this new development URL and port to your Allowed CORS Origins list or the Studio will not be able query data from your project.
If you're seeing this error, it means that the CLI can not identify your Sanity project context.
To fix this, try the following:
- Ensure that you're running the command within the correct directory. Your Sanity project directory should have a
package.json
and asanity.json
file. - Ensure that you have all of the necessary dependencies installed. Do this by running a
npm install
oryarn install
if you're managing your dependencies with yarn. - Delete your
node_modules
folder, reinstall the project's dependencies, and try running the command again.
If these solutions don't solve the issue, please get in contact with us either through the feedback form at the bottom of the page or our Slack community.
If you're seeing this error, it's likely that you're on a Windows computer with insufficient permissions for installing dependencies with npm
.
To fix this, try:
- Running your command line program as an Administrator
- Run
npm cache clean --force
andnpm cache verify
- Uninstall and reinstall Node.js
If these solutions don't solve the issue, please get in contact with us either through the feedback form at the bottom of the page or our Slack community.
If you're seeing this error, first ensure that your sanity.cli.(js|ts)
file contains a projectId
and dataset
in the defineConfig
function. If that's not the case, add those details and retry the command you were attempting to execute.
If your sanity.cli.(js|ts)
file looks correctly setup with those attributes present, try rerunning the CLI command with npx
. For example, if you were previously trying to run sanity deploy
, try running npx sanity deploy
.
If the command executes without error, it's likely that your local CLI version is out of date. Try upgrading with npm i -g @sanity/cli
.
If these solutions don't solve the issue, please get in contact with us either through the feedback form at the bottom of the page or our Slack community.
This error occurs when you run a command without the appropriate permissions. Common causes can be:
- Incorrect or misspelled project ID in your
sanity.json
. - You don't have the rights to deploy a project. Need to be an Administrator or have a deploy token to do this.
For example: runningsanity graphql deploy
with Write or Read+Write access only will give you this error.
This error occurs on sanity deploy
when you have access to the studio but without the required permissions to deploy.
To fix this, ensure that you are logged into the CLI with the correct credentials for your project. You can easily do this by logging out of the CLI with the following command:
npx sanity logout
And logging back in again with the following command:
npx sanity login
This can be one of several issues:
- A temporary issue, please try to run your command again.
- You have specified an invalid token with the
SANITY_AUTH_TOKEN
env variable. - The session timed out. Try to log out and log in again with the
sanity logout
andsanity login
CLI commands. - There was an issue with your logged in user. Try to logout and login again.