Is it possible to make sanity cli use npm rather than yarn?
Yes, the Sanity CLI can use npm instead of yarn! The CLI actually detects and respects your preferred package manager automatically.
When you run sanity init, the CLI has a --package-manager flag that lets you specify which package manager to use. According to the CLI documentation, you can explicitly set your preference:
sanity init --package-manager npmHowever, in most cases you don't even need to use the flag. The Sanity CLI is smart enough to detect which package manager you're using based on your project's lock files:
- If it finds
package-lock.json, it'll use npm - If it finds
yarn.lock, it'll use yarn - If it finds
pnpm-lock.yaml, it'll use pnpm
So if you want to ensure npm is used, just make sure you have a package-lock.json in your project directory before running Sanity commands.
For creating a new project with npm specifically, you can also use:
npm create sanity@latestThis ensures npm is used from the start. The same pattern works with other package managers too:
yarn create sanity@latest
pnpm create sanity@latestThe CLI will then use that same package manager for installing dependencies and for any subsequent commands that need to install packages. So once you initialize with npm, the CLI will continue using npm for that project.
Show original thread3 replies
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.