Unlock seamless workflows and faster delivery with our latest releases- get the details

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.

Common errors while installing the CLI

Error: EACCES: permission denied, access '/usr/local/lib/node_modules'

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.

Error: spawn cmd ENOENT on Windows machines

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.

Common errors while using the CLI

Port 3333 is already in use

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.

Command (start|dev|deploy|...) is not available outside of a Sanity project context

If you're seeing this error, it means that the CLI can not identify your Sanity project context.

To fix this, try the following:

  1. Ensure that you're running the command within the correct directory. Your Sanity project directory should have a package.json and a sanity.json file.
  2. Ensure that you have all of the necessary dependencies installed. Do this by running a npm install or yarn install if you're managing your dependencies with yarn.
  3. 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.

Command failed with exit code 1 (EPERM): npm install next-sanity@7

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:

  1. Running your command line program as an Administrator
  2. Run npm cache clean --force and npm cache verify
  3. 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.

sanity.cli.(js|ts) does not contain a project identifier

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.

Unauthorized - You do not have access to the project with ID <projectID>

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: running sanity graphql deploy with Write or Read+Write access only will give you this error.

Unauthorized - User is missing required grant sanity.project/deployStudio to perform this operation

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

Unauthorized - Session not found

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 and sanity login CLI commands.
  • There was an issue with your logged in user. Try to logout and login again.

Was this article helpful?