# Deploying a monorepo via serverless CI/CD service with yarn workspaces

**URL:** <https://forum.serverless.com/t/deploying-a-monorepo-via-serverless-ci-cd-service-with-yarn-workspaces/12507>\
**Category:** Serverless Framework\
**Tags:** cicd\
**Created:** [September 8, 2020, 10:23pm UTC](https://forum.serverless.com/t/deploying-a-monorepo-via-serverless-ci-cd-service-with-yarn-workspaces/12507 "2020-09-08T22:23:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![danb235](https://avatars.discourse-cdn.com/v4/letter/d/47e85d/32.png) [@danb235](https://forum.serverless.com/u/danb235)\
**Post date:** [September 8, 2020, 10:23pm UTC](https://forum.serverless.com/t/deploying-a-monorepo-via-serverless-ci-cd-service-with-yarn-workspaces/12507/1 "2020-09-08T22:23:31Z")

</div>

I have a monorepo with 2 nodejs services and a shared resource configured via yarn workspaces:

- `/services/service1`
- `/services/service2`
- `/packages/shared`

Locally, when I run `yarn`, I’m able to import packages from `/packages/shared` in any of the services (and deploy via the cli without issue). When deploying via the serverless CI/CD service, I encounter errors because the shared resource is not available. A couple of thoughts:

- The serverless CI flow enforces the usage of `npm install` to install node modules, as far as I can tell I cannot change this to `yarn`?
- NPM does not support workspaces, so the `/packages/shared` aren’t available to the services
- I attempted to run `yarn` as a post install step, which caused errors and failed (not to mention this is awful). Support referred me to [https://www.serverless.com/framework/docs/dashboard/cicd/custom-scripts/](https://www.serverless.com/framework/docs/dashboard/cicd/custom-scripts/) that led me to this but I haven’t figured out a working solution yet.

The serverless documentation for monorepos includes a shared directory [https://www.serverless.com/framework/docs/dashboard/cicd/mono-repo/](https://www.serverless.com/framework/docs/dashboard/cicd/mono-repo/) yet I don’t see any reference for how to deploy services via the serverless CI/CD and have access to the shared code dependancy. Can anyone help me shine some light on how this should be properly setup?

tl;dr: I have a nodejs monorepo setup using yarn workspaces. I am unable to deploy services via the serverless CI/CD service that requires workspace access that yarn provides. What’s the proper way to set this up?

---

<div class="post-metadata">

**Author:** ![danb235](https://avatars.discourse-cdn.com/v4/letter/d/47e85d/32.png) [@danb235](https://forum.serverless.com/u/danb235)\
**Post date:** [September 8, 2020, 10:29pm UTC](https://forum.serverless.com/t/deploying-a-monorepo-via-serverless-ci-cd-service-with-yarn-workspaces/12507/2 "2020-09-08T22:29:26Z")

</div>

I found a repo that is setup similar to my own: [https://github.com/AnomalyInnovations/serverless-lerna-yarn-starter](https://github.com/AnomalyInnovations/serverless-lerna-yarn-starter)

In the case above, for example, how would each service be deployed via the serverless CI/CD if they don’t have yarn workspace access to the code resource in `/packages/sample-package/`?

---

<div class="post-metadata">

**Author:** ![danb235](https://avatars.discourse-cdn.com/v4/letter/d/47e85d/32.png) [@danb235](https://forum.serverless.com/u/danb235)\
**Post date:** [September 9, 2020, 8:34pm UTC](https://forum.serverless.com/t/deploying-a-monorepo-via-serverless-ci-cd-service-with-yarn-workspaces/12507/3 "2020-09-09T20:34:46Z")

</div>

Quick update on this, it turns out that if a `yarn.lock` file exists with a service in a monorepo, the serverless ci/cd service will use `yarn` instead of `npm install`. It’s hacky, but placing an empty `yarn.lock` file in each service works.

---

<div class="post-metadata">

**Author:** ![s1mrankaur](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/s1mrankaur/32/4850_2.png) [@s1mrankaur](https://forum.serverless.com/u/s1mrankaur)\
**Post date:** [January 15, 2021, 12:42am UTC](https://forum.serverless.com/t/deploying-a-monorepo-via-serverless-ci-cd-service-with-yarn-workspaces/12507/4 "2021-01-15T00:42:28Z")

</div>

@danb235 I am trying to do the same thing. I am using the Serverless framework but not serverless CI/CD. We use npm and haven’t used yarn for anything yet.

1. We need to ensure that our services are deployed individually and the downstream services get deployed before the upstream once.
2. Also, that only the services with changed code should be deployed.

Can you recommend how should yarn be used here and what for exactly? I have been through the same example as well but it uses yarn and seed
