Build monorepo project on netlify

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:

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 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.
https://app.netlify.com/sites/dazzling-joliot-a3537c/deploys/5d99be3526997000086a161a

Any ideas what to do?

Thank you,
Christian

@chrfritsch, welcome to our Netlify community site. :slightly_smiling_face:

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

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

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.

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

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/

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.

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

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

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