Using Yarn.lock or Package-lock.json with Sanity Studio

3 replies
Last updated: Apr 15, 2021
Would it be possible to have the Sanity CLI respect the presence of either
yarn.lock
or
package-lock.json
and when a single lock file is present… Use that package manager? We use NPM basically everywhere and I’d love to not need to use
yarn
strictly when dealing with a Sanity Studio project.
It is a small thing, but as a paid product it would be a nice touch if this wasn’t an area we didn’t need to adjust our normal work flow.
AI Update

I understand your frustration! Based on the official Sanity CLI documentation, the sanity init command does include a --package-manager flag that lets you specify which package manager to use.

However, I need to be honest: the official documentation doesn't explicitly state whether the CLI automatically detects lock files. The docs only mention that you can specify a package manager manually with the flag.

If the CLI isn't respecting your package-lock.json file automatically, here are your options:

1. Use the explicit flag during initialization:

sanity init --package-manager npm

2. Use npm's create command instead:

npm create sanity@latest

This approach uses npm's native project scaffolding, which should respect your npm workflow.

3. For existing projects: If you already have a Sanity project and want to ensure npm is used for all operations:

  • Delete any yarn.lock file if it exists
  • Run npm install to generate/update your package-lock.json
  • Use npm commands (npm run dev, npm install, etc.) going forward

The Sanity CLI commands like sanity dev and sanity deploy should work fine regardless of which package manager installed the dependencies.

About your feedback as a paid customer: Your point is valid. Many modern CLI tools (like Create React App, Vite, etc.) do automatically detect lock files, and it would be a nice quality-of-life improvement if Sanity's CLI had more explicit documentation about this behavior—or better automatic detection if it's not already implemented.

If this is a significant pain point for your team, I'd recommend opening a feature request on the Sanity GitHub discussions or reaching out to Sanity support. They're generally responsive to customer feedback, especially from paid plan users.

We agree with the assertion and it's oft requested. Just a matter of finding the time.
I keep messing up my studio by running
npm i
then scratch my head for a minute when the studio crashes until I remember that I can’t use
npm
in the studio
You can also follow this issue on GH https://github.com/sanity-io/sanity/issues/716

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?