Is it possible to make sanity cli use npm rather than yarn?

3 replies
Last updated: Oct 14, 2020
Anyone know if it’s possible to make sanity cli use
npm
rather than
yarn
?
AI Update

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 npm

However, 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@latest

This ensures npm is used from the start. The same pattern works with other package managers too:

yarn create sanity@latest
pnpm create sanity@latest

The 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 thread
3 replies
Using both hasn't hurt so far, but it does feel like being able to choose npm would be more comfortable.
the cli is locked to yarn for now, but we do want to change this!
Trying our best to get away from facebook tech

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?