# Build monorepo project on netlify

**URL:** <https://answers.netlify.com/t/build-monorepo-project-on-netlify/3975>\
**Category:** Support\
**Tags:** monorepo\
**Created:** [October 6, 2019, 10:37am UTC](https://answers.netlify.com/t/build-monorepo-project-on-netlify/3975 "2019-10-06T10:37:07Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrfritsch](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/chrfritsch/32/3320_2.png) [@chrfritsch](https://answers.netlify.com/u/chrfritsch)\
**Post date:** [October 6, 2019, 10:37am UTC](https://answers.netlify.com/t/build-monorepo-project-on-netlify/3975/1 "2019-10-06T10:37:07Z")

</div>

Hello,

I am working on a monorepo gatsby project that I would like to deploy on Netlify. I am using yarn workspaces to manage the different projects in one repo. I’ve set up a demo repo to show my problem:  
[https://github.com/chrfritsch/netlify-monorepo](https://github.com/chrfritsch/netlify-monorepo)

In netlify I configured the example folder as base directory. The example project has a dependency on the theme project. The theme project is not published on npm.

I’ve read on [Build configuration overview | Netlify Docs](https://www.netlify.com/docs/continuous-deployment/#build-settings) that there is some kind of monorepo support now.

The deployment fails, because the theme project is not published on npm. And I don’t want to do that.

> **[Netlify App](https://app.netlify.com/sites/dazzling-joliot-a3537c/deploys/5d99be3526997000086a161a)**
>
> Start building the best web experiences in record time

Any ideas what to do?

Thank you,  
Christian

---

<div class="post-metadata">

**Author:** ![luke](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/luke/32/39_2.png) [@luke](https://answers.netlify.com/u/luke)\
**Post date:** [October 8, 2019, 6:42am UTC](https://answers.netlify.com/t/build-monorepo-project-on-netlify/3975/2 "2019-10-08T06:42:31Z")

</div>

@chrfritsch, welcome to our Netlify community site. 🙂

Is this a private NPM package? If so, the following topic may have the solution:

> [@\[Support Guide\] Using private NPM modules on Netlify](https://answers.netlify.com/t/common-issue-using-private-npm-modules-on-netlify/795):
>
> Last reviewed by Netlify Support: December 2022 You want to build your site on Netlify but you have some private npm modules served from [npmjs.org](http://npmjs.org), and now you’re wondering how you can access them during build? The most straightforward way to do this is two steps: Find your token inside the ~/.npmrc file in your home folder and set it as an NPM\_TOKEN environment variable through Netlify’s admin UI. This will be on the Build & Deploy settings page of your site configuration, in the section c…

If not, or if there are other questions, please let us know.

---

<div class="post-metadata">

**Author:** ![chrfritsch](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/chrfritsch/32/3320_2.png) [@chrfritsch](https://answers.netlify.com/u/chrfritsch)\
**Post date:** [October 8, 2019, 7:19am UTC](https://answers.netlify.com/t/build-monorepo-project-on-netlify/3975/3 "2019-10-08T07:19:10Z")

</div>

It’s not a private npm package, it’s a monorepo. All packages are in the same repository. I want to deploy the example packages, which uses the theme package.

I think the problem is, that the example package does not have a yarn.lock. Because lock files are stored in the root directory in monorepos. And because there is no lock file, netlify tries to build via npm instead of yarn.

---

<div class="post-metadata">

**Author:** ![marcus](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/marcus/32/2651_2.png) [@marcus](https://answers.netlify.com/u/marcus)\
**Post date:** [October 8, 2019, 10:56am UTC](https://answers.netlify.com/t/build-monorepo-project-on-netlify/3975/4 "2019-10-08T10:56:10Z")

</div>

In case of monorepos that use yarn workspace I guess using `base` is not what you want.

Our monorepo feature is built for repos that have their frontend in a subdirectory along with the yarn.lock  
E.g. a Golang backend that has docs in `/docs` or a microservice architecture with the frontend in the same repo under `/frontend`  
For these kinds of sites the `base` setting is crucial, because otherwise our buildbot can’t detect & cache dependencies.

You have several options:

- Use e.g. `yarn build` as a build command which will run it in all packages, detecting dependencies correctly
- Use `yarn --cwd packages/package_to_deploy build` for running a command from a specific package

---

<div class="post-metadata">

**Author:** ![chrfritsch](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/chrfritsch/32/3320_2.png) [@chrfritsch](https://answers.netlify.com/u/chrfritsch)\
**Post date:** [October 8, 2019, 11:27am UTC](https://answers.netlify.com/t/build-monorepo-project-on-netlify/3975/5 "2019-10-08T11:27:15Z")

</div>

Using something like `yarn workspace example build` in the base directory builds at least the site. But caching doesn’t work. So on every build netlify does a full yarn install. I think it’s because in example/node\_modules/.bin there are some symbolic links to /node\_modules/

---

<div class="post-metadata">

**Author:** ![chrfritsch](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/chrfritsch/32/3320_2.png) [@chrfritsch](https://answers.netlify.com/u/chrfritsch)\
**Post date:** [October 9, 2019, 1:16pm UTC](https://answers.netlify.com/t/build-monorepo-project-on-netlify/3975/6 "2019-10-09T13:16:15Z")

</div>

Any further ideas? I would really like to use Netlify for my project. It’s a multisite project where 10 sub-sites are sharing one local gatsby-theme.

With 10 sites in one Netlify team, 300min of build time are pretty precious.

---

<div class="post-metadata">

**Author:** ![perry](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/perry/32/16_2.png) [@perry](https://answers.netlify.com/u/perry)\
**Post date:** [October 9, 2019, 10:16pm UTC](https://answers.netlify.com/t/build-monorepo-project-on-netlify/3975/7 "2019-10-09T22:16:36Z")

</div>

hey @chrfritsch - did you see this? just out!

> **[Launching Monorepo support for Netlify sites](https://www.netlify.com/blog/2019/10/09/launching-monorepo-support-for-netlify-sites/)**
>
> Supporting monorepos has been a long-standing feature request among our customers. Before today, there was no easy way to use the same repository and deploy it across multiple Netlify sites.

---

<div class="post-metadata">

**Author:** ![chrfritsch](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/chrfritsch/32/3320_2.png) [@chrfritsch](https://answers.netlify.com/u/chrfritsch)\
**Post date:** [October 10, 2019, 6:34am UTC](https://answers.netlify.com/t/build-monorepo-project-on-netlify/3975/8 "2019-10-10T06:34:21Z")

</div>

Yes, but that doesn’t help. That’s for repos that have completely different projects in one repo, like @marcus mentioned earlier.

I think what really needs to be fixed is [https://github.com/netlify/build-image/issues/196](https://github.com/netlify/build-image/issues/196)

---

<div class="post-metadata">

**Author:** ![futuregerald](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/futuregerald/32/33_2.png) [@futuregerald](https://answers.netlify.com/u/futuregerald)\
**Post date:** [October 14, 2019, 7:21pm UTC](https://answers.netlify.com/t/build-monorepo-project-on-netlify/3975/9 "2019-10-14T19:21:20Z")

</div>

Thanks @chrfritsch, and I agree. Thanks for chiming in there in that issue.

---

<div class="post-metadata">

**Author:** ![jchiatt](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/jchiatt/32/7910_2.png) [@jchiatt](https://answers.netlify.com/u/jchiatt)\
**Post date:** [March 14, 2020, 5:48am UTC](https://answers.netlify.com/t/build-monorepo-project-on-netlify/3975/10 "2020-03-14T05:48:38Z")

</div>

Any update on this? I’m also trying to configure deployment pipeline for a monorepo using Yarn Workspaces where each package (other than one called `shared`) is a separate static site. But I only have one lockfile at the monorepo root so I’m unable to set things up.

---

<div class="post-metadata">

**Author:** ![fool](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/fool/32/37_2.png) [@fool](https://answers.netlify.com/u/fool)\
**Post date:** [March 17, 2020, 9:29pm UTC](https://answers.netlify.com/t/build-monorepo-project-on-netlify/3975/11 "2020-03-17T21:29:49Z")

</div>

No updates on this feature, no. I guess I don’t understand why your build fails exactly; it’s possible we can help you find a workaround (it wouldn’t be brilliant, but it could likely work). Regardless, as promised, we’ll post here if things change (or you can follow this issue: [Support for monorepos, including lerna or yarn workspaces · Issue #196 · netlify/build-image · GitHub](https://github.com/netlify/build-image/issues/196))

PR’s are welcome if you have a suggestion about how to better implement it though! This is likely the only file that would need changing:

> <https://github.com/netlify/build-image/blob/xenial/run-build-functions.sh>
