Clarification on using Lerna for package management

2 replies
Last updated: Apr 24, 2020
does
lerna run build --parallel
run
npm i
in each submodule directory before it tries to build?
AI Update

This question is about Lerna, a JavaScript monorepo management tool, and isn't specifically related to Sanity. You might get better answers in a general JavaScript/Node.js community forum.

That said, to directly answer: No, lerna run build --parallel does not automatically run npm install in each package. The lerna run command only executes the specified npm script in packages that have it defined—it assumes dependencies are already installed.

You need to install dependencies separately first:

# Install dependencies first
lerna bootstrap
# OR
npm install  # (if using npm workspaces)

# Then run build
lerna run build --parallel

If you're asking this because you're working with a Sanity project that uses Lerna (some older Sanity monorepo setups do), the same principle applies—you'll need to run the dependency installation step before building.

For Sanity-specific questions about project setup, Studio configuration, GROQ queries, Content Lake, or any other Sanity features, I'm here to help! Feel free to ask anything related to Sanity's platform, APIs, or integrations.

Hi
user M
! Lerna can be challenging sometimes.

lerna run build
will only run
npm run build
in every package, and will not install any dependencies for you. You're probably looking for
lerna bootstrap
, which will run
npm install
in every package.
Cheers 🙂
I feel like the build that comes with the sapper starter is lacking the bootstrap step, I've added it to the main package.json so I'll let you know how I fare

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?