Issue with deploying a project using yarn instead of npm, resolved by adding a configuration to lerna.json file.

12 replies
Last updated: Apr 18, 2021
Having a strange deploy issue on a new project.
I'm using yarn instead of npm, so I deleted any of the package-lock files already. I get this error when deploying after most of the process goes smoothly:


348 PM: npm ERR! cipm can only install packages with an existing package-lock.json or npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm@5 or later to generate it, then try again.
I do have yarn.lock files that have a version of 1 at the top of them, so I can't figure out why this isn't sufficient.

Any thoughts of things to try?
AI Update

This is a classic mismatch between your local package manager (yarn) and what the deployment environment is trying to use (npm). The error message about cipm (a now-deprecated npm command) indicates that your deployment platform is trying to use npm to install packages, but it's looking for package-lock.json which doesn't exist because you're using yarn.

Here are some things to try:

1. Check your deployment platform's settings

If you're deploying to Netlify, Vercel, or another hosting platform (not using sanity deploy), you need to tell it to use yarn instead of npm. Look for:

  • A build settings section where you can specify the package manager
  • Environment variables like NPM_USE_YARN=true or similar
  • Build command configuration - make sure it's using yarn commands, not npm

2. Add a .npmrc or configuration file

Some platforms detect the package manager automatically if you add a .yarnrc file or specify it in your project configuration. Check your platform's documentation for how to specify yarn as the package manager.

3. If using sanity deploy directly

The sanity deploy command should handle this automatically, but if you're seeing this error, try:

  • Making sure your package.json scripts use yarn: "deploy": "sanity deploy"
  • Running yarn install locally first to ensure your yarn.lock is up to date
  • Checking if there are any cached node_modules or lock files that need clearing

4. Switch to npm (if needed)

If the deployment platform doesn't support yarn well, you could:

  • Delete yarn.lock
  • Run npm install to generate a package-lock.json
  • Commit the package-lock.json file
  • Use npm commands going forward

5. Check for hidden lock files

Sometimes package-lock.json files hide in subdirectories. Run:

find . -name "package-lock.json" -type f

And delete any you find if you want to stick with yarn.

The key issue is that your deployment environment is configured to use npm but your project is set up for yarn. You need to either configure the deployment to use yarn, or switch your project to npm. If you let me know which platform you're deploying to, I can give more specific guidance!

It looks like that error comes from cipm, which I think requires a package-lock.json file (not a yarn.lock file). When you deleted package-lock.json did you also rimraf or delete node_modules? Where are you deploying?
i was having a lot of dependency issues so I deleted the cache/node_modules/package-lock at some point and restarted fresh with yarn
the deployment is the auto-setup one with netlify from the gatsby/sanity demo project
Did you first try to use NPM to deploy? In that case, your Netlify build settings may still be configured with NPM.
I suppose that's the default? This is the first time since the initial setup process that I'm trying to deploy.
Did you first try to use NPM to deploy? In that case, your Netlify build settings may still be configured with NPM.
It looks like that error comes from cipm, which I think requires a package-lock.json file (not a yarn.lock file). When you deleted package-lock.json did you also rimraf or delete node_modules? Where are you deploying?
i was having a lot of dependency issues so I deleted the cache/node_modules/package-lock at some point and restarted fresh with yarn
the deployment is the auto-setup one with netlify from the gatsby/sanity demo project
Figured it out! Thanks for the effort Geoff.
So, initially the build process was auto-detecting yarn and installing packages with yarn, but then when running 'lerna bootstrap' it defaults to npm.

The solution was to add '"npmClient": "yarn",' to my lerna.json file in my root directory.
Great! Glad you got it working. 🙂

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?