# Using serverless with yarn workspaces

**URL:** <https://forum.serverless.com/t/using-serverless-with-yarn-workspaces/4560>\
**Category:** Serverless Framework\
**Created:** [May 24, 2018, 2:53pm UTC](https://forum.serverless.com/t/using-serverless-with-yarn-workspaces/4560 "2018-05-24T14:53:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucasowens](https://avatars.discourse-cdn.com/v4/letter/l/f6c823/32.png) [@lucasowens](https://forum.serverless.com/u/lucasowens)\
**Post date:** [May 24, 2018, 2:53pm UTC](https://forum.serverless.com/t/using-serverless-with-yarn-workspaces/4560/1 "2018-05-24T14:53:58Z")

</div>

I am trying to setup a monorepo for a large serverless project. When using yarn workspaces a node\_modules folder is created in the root of the repo. All of the shared modules are hoisted into this node\_modules and the node\_modules folder in the individual serverless applications only contain the unique versions of specific modules. When I deploy or package my application all of the modules that are in the root node\_modules folder are missing.

Is there a way to tell serverless to look in each node\_modules directory until it hits the repository root?

thanks,

Luke

---

<div class="post-metadata">

**Author:** ![RyanMcDonald](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/ryanmcdonald/32/920_2.png) [@RyanMcDonald](https://forum.serverless.com/u/RyanMcDonald)\
**Post date:** [May 24, 2018, 6:33pm UTC](https://forum.serverless.com/t/using-serverless-with-yarn-workspaces/4560/2 "2018-05-24T18:33:54Z")

</div>

I ran into this as well. I don’t think Serverless has a way to handle this itself, so I had to disable the hoisting feature of Yarn Workspaces:

```
"workspaces": {
  "packages": [
    "packages/*",
  ],
  "nohoist": [
    "**"
  ]
},

```

See [here](https://yarnpkg.com/blog/2018/02/15/nohoist/) for more info on nohoist.

---

<div class="post-metadata">

**Author:** ![tommedema](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/tommedema/32/1257_2.png) [@tommedema](https://forum.serverless.com/u/tommedema)\
**Post date:** [August 21, 2018, 5:04am UTC](https://forum.serverless.com/t/using-serverless-with-yarn-workspaces/4560/3 "2018-08-21T05:04:50Z")

</div>

This is very suboptimal but I had to go with Ryan’s advice too.

I made it a little more specific:

```
"nohoist": [
      " **/serverless-*/**"
]

```

But there are significant issues, most notably that dev dependencies are bundled with your app: [https://github.com/serverless/serverless/pull/3889#issuecomment-414547166](https://github.com/serverless/serverless/pull/3889#issuecomment-414547166)

---

<div class="post-metadata">

**Author:** ![martin-css](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/martin-css/32/2532_2.png) [@martin-css](https://forum.serverless.com/u/martin-css)\
**Post date:** [September 13, 2018, 3:56pm UTC](https://forum.serverless.com/t/using-serverless-with-yarn-workspaces/4560/4 "2018-09-13T15:56:18Z")

</div>

We use Yarn Workspaces at our company ([butterwire](https://www.butterwire.com)) as all our JS code is in a mono repo.

We created a small plugin to help use serverless without requiring to use nohoist, for the reasons mentioned above. It might have some rough edges but hopefully it’s useful to some.

> **[GitHub - Butterwire/serverless-plugin-monorepo: A Serverless plugin that...](https://github.com/Butterwire/serverless-plugin-monorepo)**
>
> A Serverless plugin that allows use of serverless in a JS mono repo. - GitHub - Butterwire/serverless-plugin-monorepo: A Serverless plugin that allows use of serverless in a JS mono repo.

---

<div class="post-metadata">

**Author:** ![jamiearonson](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/jamiearonson/32/1921_2.png) [@jamiearonson](https://forum.serverless.com/u/jamiearonson)\
**Post date:** [November 15, 2018, 6:12pm UTC](https://forum.serverless.com/t/using-serverless-with-yarn-workspaces/4560/5 "2018-11-15T18:12:01Z")

</div>

Thank you!!! This is what I’ve been looking for!

---

<div class="post-metadata">

**Author:** ![kempsterrrr](https://avatars.discourse-cdn.com/v4/letter/k/58f4c7/32.png) [@kempsterrrr](https://forum.serverless.com/u/kempsterrrr)\
**Post date:** [April 22, 2019, 12:55pm UTC](https://forum.serverless.com/t/using-serverless-with-yarn-workspaces/4560/6 "2019-04-22T12:55:08Z")

</div>

Does anyone have an example of how to create a project with yarn workspaces and serverless-plugin-monorepo?

---

<div class="post-metadata">

**Author:** ![danrivett](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/danrivett/32/4304_2.png) [@danrivett](https://forum.serverless.com/u/danrivett)\
**Post date:** [June 2, 2020, 9:04pm UTC](https://forum.serverless.com/t/using-serverless-with-yarn-workspaces/4560/7 "2020-06-02T21:04:07Z")

</div>

Although I’ve had success using `serverless-plugin-monorepo` packaging up the hoisted dependencies, I’m still running into issues packaging up local packages not published to an external repo.

Local builds work fine, but `serverless package` errors with:

```
Error --------------------------------------------------

  yarn install --frozen-lockfile --non-interactive failed with code 1
  error An unexpected error occurred: "https://registry.yarnpkg.com/@private-package/foo: Not found".

```

I’m using `serverless-webpack` and it seems the issue lies with that plugin? I switched to `serverless-jetpack` and it packaged and deployed correctly, but I’d prefer to manage the packaging of the lambda with webpack for minification etc if possible.

---

<div class="post-metadata">

**Author:** ![Joseph](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@Joseph](https://forum.serverless.com/u/Joseph)\
**Post date:** [June 7, 2020, 5:20pm UTC](https://forum.serverless.com/t/using-serverless-with-yarn-workspaces/4560/8 "2020-06-07T17:20:35Z")

</div>

Hi DanRivett, I’m also facing the same issue. After switching to serverless-jetpack, it seems bundling is working however, I’m not able to apply babel to convert the ES6 code to commonjs and so it fails during runtime. Any thoughts on how to do that? With webpack such things were explicit configurations.
