EPERM error when installing Sanity with npm --legacy-peer-deps

2 replies
Last updated: Apr 10, 2024
Hi there everyone! Battling to install Sanity into my project. This is the error that I am getting at the moment:
Error: Command failed with exit code 1 (EPERM): npm install --legacy-peer-deps --save @sanity/vision@3 sanity@3 @sanity/image-url@1 styled-components@6

I don’t know if anyone has run into this command but I would really appreciate any advice - huge blocker for me at the moment
😆
AI Update

The EPERM error you're encountering is a permissions issue on Windows when trying to install Sanity packages. This is actually documented in Sanity's official CLI errors documentation, and there are several solutions you can try:

Quick Fixes to Try

1. Run as Administrator The most straightforward solution is to run your terminal/command prompt as an Administrator. Right-click on your terminal application and select "Run as Administrator", then try the installation again.

2. Clear npm cache Sometimes cached data can cause permission issues:

npm cache clean --force
npm cache verify

3. Reinstall Node.js If the above doesn't work, try completely uninstalling and reinstalling Node.js. This often resolves underlying permission configuration issues.

4. Use a package manager alternative If you're still stuck, try using pnpm or yarn instead of npm, as they handle permissions differently:

# Using pnpm
pnpm install @sanity/vision@3 sanity@3 @sanity/image-url@1 styled-components@6

# Or using yarn
yarn add @sanity/vision@3 sanity@3 @sanity/image-url@1 styled-components@6

Windows-Specific Issue

The --legacy-peer-deps flag in your command suggests there might also be dependency conflicts. On Windows, EPERM errors are commonly related to the $PATH environment variable or file system permissions. Make sure your user account has write permissions to the npm directories.

If none of these solutions work, the Sanity community Slack is very responsive and can help troubleshoot Windows-specific installation issues. The feedback form on the docs page is also monitored by the team.

Show original thread
2 replies
nvm cleared my npm’s cache and reran the install and it worked
yeah, you really need that --legacy-peer-deps, else it fails as too many legacy dependencies

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?