Troubleshooting issues with using the Sanity CLI on an M1 Mac and finding a workaround.
28 replies
Last updated: Jan 28, 2022
S
Hey folks! Anyone have any experience using the Sanity CLI with an M1 Mac? I’m trying to resurrect an old project and trying to upgrade all dependencies but it seems like the CLI just doesn’t wanna run. This project was bootstrapped from the Gatsby blog starter
Jan 27, 2022, 10:48 PM
Hey User! This thread from a few days ago might have a solution for you!
Jan 27, 2022, 11:13 PM
S
Thanks User, seems like that conversation is more about node-gyp? Unless I’m understanding the logs wrong, there’s something wrong with
sanity cliitself? It always fails to resolve dependencies. I’ve tried running it from both the root folder as well as the studio folder
Jan 27, 2022, 11:22 PM
S
In the meantime, is there a workaround to updating studio dependencies without the CLI?
Jan 27, 2022, 11:26 PM
It looks like you haven't installed Sanity based off of that error. If you cloned a repo or are working directly from the create flow for the starter, did you run
If that isn't the case, the only other report I've seen of folks having issue with the Studio on an M1 is that thread I shared, so I would think it's unlikely an issue with the CLI and more an issue with your particular machine. I could be wrong though! In particular, did you
read this reply to the thread I shared describing how they got the same starter to work on their M1?
npm ibefore trying to run
sanity install?
If that isn't the case, the only other report I've seen of folks having issue with the Studio on an M1 is that thread I shared, so I would think it's unlikely an issue with the CLI and more an issue with your particular machine. I could be wrong though! In particular, did you
read this reply to the thread I shared describing how they got the same starter to work on their M1?
Jan 27, 2022, 11:33 PM
J
From my own experiences with node on the m1, I would suggest uninstalling node (and related package managers) and avoid the homebrew install, which defaults to node v17 and installs into the /lib/homebrew directory.
I’ve installed nvm (via homebrew) and use the current v16 LTS for best results on my m1.
You’ll then want to install the latest cli with
I’ve installed nvm (via homebrew) and use the current v16 LTS for best results on my m1.
You’ll then want to install the latest cli with
npm install -g @sanity/cli- and you should not need to use sudo for any of this if you have the xcode tools needed when you installed homebrew.
Jan 28, 2022, 12:39 AM
J
I may advise also installing yarn.
npm install --global yarn
Jan 28, 2022, 12:40 AM
J
I’m sure someone out there has a more elegant solution to my own ‘nuke it from orbit and re-install via effectively another third party package manager’ method, but at least this keeps all node services within the same family and has worked well for me.
Jan 28, 2022, 12:42 AM
S
Yup, I ran
npm ifrom the root directly and that ran just fine. I’ve had issues with node in the past, when I first initially tried to install node. Not entirely sure what I ended up doing to finally getting it to work. I’m not super well versed with node and nvm,
user S
, is there a guide I can follow to properly uninstall and reinstall node through nvm?
Jan 28, 2022, 12:55 AM
S
user S
I just ran npm iin studio and then tried
sanity installagain and it returns the same thing. Perhaps it is indeed something with brew
Jan 28, 2022, 12:58 AM
S
user S
I just ran npm iin studio and then tried
sanity installagain and it returns the same thing. Perhaps it is indeed something with brew
Jan 28, 2022, 12:58 AM
I believe you can uninstall node using . Then to reinstall you would run
nvm deactivatethen
nvm uninstall <your-version-number>
nvm install --lts.
Jan 28, 2022, 1:06 AM
S
Just uninstalled and reinstalled the LTS using NVM. Reinstall Sanity CLI and then
npm installand then finally
sanity installand I’m still getting the same issue 😞
Jan 28, 2022, 1:22 AM
J
This issue can be pretty frustrating because one has to balance multiple repo services, the operating system quirks, and the project build. I feel your pain with all of this.
Since your error still appears to be looking in
b. the node_module data in that repo is now out of date and should be deleted and rebuilt
My personal approach if this was my machine would be:
1. try
• check
• log into
https://www.sanity.io/manage and you should see the new test project and your existing one4. run
Since your error still appears to be looking in
/opt/homebrew…for the sanity cli, I would bet that this is because:a. your previous node install with homebrew wasn’t completely removed and/or
b. the node_module data in that repo is now out of date and should be deleted and rebuilt
My personal approach if this was my machine would be:
1. try
brew remove nodeagain, then
brew doctor, fix any outstanding issues if any then reboot to be sure2. we want to continue removing ‘cached’ data. in your studio directory, run
rm -rf node_modulesthis dir should be safe to remove3. set asside recovery of this studio build and start a new studio install to test.
• check
node -vto see if it’s still correct• run
npm install -g @sanity/cliagain to be sure it’s installed • run
sanity -hto test that the cli path is correct, you should see some basic available commands• create a new directory
mkdir ~/test && cd ~/test, then
sanity login, then
sanity init• create a new test project, you can use one of the starter schemas here too
• log into
https://www.sanity.io/manage and you should see the new test project and your existing one4. run
sanity install && sanity starton your new test studio - this should work if you’ve made it this far. Now you have an existing working and updated schema. You can try
sanity installon your existing studio build. You can also swap in your existing projectId and dataset into the new studio install (in sanity.json) and use the vision tool to browse any data or just swap in your previous schema builds to the new studio install.
Jan 28, 2022, 2:43 AM
J
Another tip, if you’ve recovered this studio build from git from an old pc or intel mac to a new m1, make sure that you weren’t syncing node_modules to your repository. If node_modules made it into your repository, you will want to clean this out (
git rm -r node_modulesthen git add/push to remove them from the remote repo)
Jan 28, 2022, 2:47 AM
S
user S
, thank you so much for taking the time to help me debug this and writing out all those detailed steps. I’ve followed along but it’s still failing specifically at the “Resolving Dependencies” stage. Now it’s complaining about the something in /.nvm/versions/node/v16.13.0
Jan 28, 2022, 3:09 AM
J
It is acting like sanity-cli isn’t installed. Do you get anything back when you enter
sanity versions?
Jan 28, 2022, 3:12 AM
S
It keeps complaining about running
sanity installbut never actually lets me successfully run it because it fails at the dependency stage
Jan 28, 2022, 3:13 AM
J
ignore my commandline tweaks - here is why my current node environment looks like on my m1• and in a working studio install I’m playing with now
Jan 28, 2022, 3:22 AM
S
Seems like those are all the latest versions of the dependencies. Now if I could only get sanity-cli to install…
Back to one of my earlier questions, is there a workaround to installing these without sanity-cli?
Back to one of my earlier questions, is there a workaround to installing these without sanity-cli?
Jan 28, 2022, 4:09 AM
S
Just in case this is helpful:
Jan 28, 2022, 4:49 AM
There might be an error in a package.json or a lockfile or something that could be causing issues - sorry about the lack of details in that error message
Jan 28, 2022, 5:28 AM
S
Interesting, so by extension
sanity upgradeis just
npm upgrade? All I’m trying to do is run a upgrade all on the dependencies so I can start working on the project. If I can avoid sanity-cli altogether, I can just do that
Jan 28, 2022, 4:55 PM
S
Alright, seems like I just needed to do
npm installand now sanity cli doesn’t complain anymore. And is happy to resolve dependencies now! So weird.
Jan 28, 2022, 4:56 PM
J
I’m so happy things seem to be working now, User. I’m pretty fascinated about how much repo and tooling management is or isn’t taught to new developers, as I’ve had to dig into a lot of this on my own time between classes and work experience. Thanks for bearing with me with our little back and forth to get you working.
Jan 28, 2022, 10:36 PM
S
Thank you
user S
, I really appreciate you taking the time to help me debug this. I should be the one thanking you! I’m actually a designer, and a 100% self taught developer, so I likely have large gaps than more new/junior developers. Perhaps one day I’ll find the time to learn this and git to a decent extent!Jan 28, 2022, 11:47 PM
S
I’d mention that while sanity cli wasn’t complaining anymore, it might’ve had something to do with just bypassing it overall and using
npm. I just tried running
sanity install @sanity/color-inputand it threw up that same error. Managed to
npm install @sanity/color-inputjust fine.
Jan 28, 2022, 11:48 PM
J
oh that is really frustrating - I’m not actually suggesting this, but I have a personal habit of backing up and defaulting then manually recovering my desktop OS. I keep a list of repos and apps to reinstall, manually move over big media or game directories. And some day I’ll have a fully working dotfile management system for myself. As I find these little quirks and methods, it helps keep config files clean and helps get me back on my feet faster when inevitable tooling issues like this crop up.
You may want to research some dotfile and dev tools management methods to help, along with tools like iterm2 and omz — but that is only a personal suggestion and strictly on you if you’re interested.
😊
You may want to research some dotfile and dev tools management methods to help, along with tools like iterm2 and omz — but that is only a personal suggestion and strictly on you if you’re interested.
😊
Jan 28, 2022, 11:55 PM
S
Thanks, I’ll definitely look into it when I get the chance!
Jan 28, 2022, 11:57 PM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.