# File '../foo.ts' is not under rootDir. rootDir is expected to contain all source files

**URL:** <https://forum.serverless.com/t/file-foo-ts-is-not-under-rootdir-rootdir-is-expected-to-contain-all-source-files/9669>\
**Category:** Serverless Framework\
**Created:** [October 21, 2019, 1:20pm UTC](https://forum.serverless.com/t/file-foo-ts-is-not-under-rootdir-rootdir-is-expected-to-contain-all-source-files/9669 "2019-10-21T13:20:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![GunterJameda](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/gunterjameda/32/3924_2.png) [@GunterJameda](https://forum.serverless.com/u/GunterJameda)\
**Post date:** [October 21, 2019, 1:20pm UTC](https://forum.serverless.com/t/file-foo-ts-is-not-under-rootdir-rootdir-is-expected-to-contain-all-source-files/9669/1 "2019-10-21T13:20:05Z")

</div>

I have a serverless app that is composed by 3 apis. They share a large amount of code. I prepared the whole application in a way that is allows me to boot every api solely or every single one of them at the same time, regarding my needs for that moment. There are some scripts to deploy the apis separately and all in once, as well.

The problem here is the shared code. As it is shared, I needed to copy them through all apis to maintain it correct, because I can’t have a folder with that code outside any of the apis. It throws the error I put in the title.

My folder structure is this one:

```
src
|- api1
   |- serverless.yml (for api1)
|- api2
   |- serverless.yml (for api2)
|- api3
   |-serverless.yml (for api3)
|- common_code_1
|- common_code_2

```

I registered those 2 folders as paths in my tsconfig.json, but it throws the error anyway. How can I share this code between apis without duplicating it?

---

<div class="post-metadata">

**Author:** ![cgrafton](https://avatars.discourse-cdn.com/v4/letter/c/b782af/32.png) [@cgrafton](https://forum.serverless.com/u/cgrafton)\
**Post date:** [January 24, 2020, 4:06pm UTC](https://forum.serverless.com/t/file-foo-ts-is-not-under-rootdir-rootdir-is-expected-to-contain-all-source-files/9669/2 "2020-01-24T16:06:00Z")

</div>

Hello! Were you able to solve this issue? I am having the same problem.

---

<div class="post-metadata">

**Author:** ![GunterJameda](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/gunterjameda/32/3924_2.png) [@GunterJameda](https://forum.serverless.com/u/GunterJameda)\
**Post date:** [January 24, 2020, 4:51pm UTC](https://forum.serverless.com/t/file-foo-ts-is-not-under-rootdir-rootdir-is-expected-to-contain-all-source-files/9669/3 "2020-01-24T16:51:24Z")

</div>

Hi!

Actually no. I did something I didn’t want to as a workaround: copied all the common code between the 3 folders. I had no time, since then, to try again and find a solution for this, but, once I do, I’ll try to post it here.

---

<div class="post-metadata">

**Author:** ![FilipPyrek](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/filippyrek/32/3920_2.png) [@FilipPyrek](https://forum.serverless.com/u/FilipPyrek)\
**Post date:** [January 25, 2020, 12:19am UTC](https://forum.serverless.com/t/file-foo-ts-is-not-under-rootdir-rootdir-is-expected-to-contain-all-source-files/9669/4 "2020-01-25T00:19:16Z")

</div>

Hi, we are using for this [Lerna](https://github.com/lerna/lerna) - monorepo package manager.

---

<div class="post-metadata">

**Author:** ![cgrafton](https://avatars.discourse-cdn.com/v4/letter/c/b782af/32.png) [@cgrafton](https://forum.serverless.com/u/cgrafton)\
**Post date:** [January 27, 2020, 7:44pm UTC](https://forum.serverless.com/t/file-foo-ts-is-not-under-rootdir-rootdir-is-expected-to-contain-all-source-files/9669/5 "2020-01-27T19:44:32Z")

</div>

Hi all, after much digging I found out that serverless does not support the pathing options offered by typescript.

For anyone else it appears the options are:

1. Copy the code as [http://forum.serverless.com/u/GunterJameda](http://forum.serverless.com/u/GunterJameda) suggested

2. Utilize Webpack to allow setting the rootDir in typescript

3. Symlink your shared module code to the each of your microservices directories. I wrote a bash script that will symlink a directory called “\_shared” to all directories one level under a parent directory called “microservices”:

or 4. Use Lerna as [http://forum.serverless.com/u/FilipPyrek](http://forum.serverless.com/u/FilipPyrek), although afaik that is only a solution for external dependencies via yarn or npm, and not internal shared modules

---

<div class="post-metadata">

**Author:** ![FilipPyrek](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/filippyrek/32/3920_2.png) [@FilipPyrek](https://forum.serverless.com/u/FilipPyrek)\
**Post date:** [January 28, 2020, 9:54am UTC](https://forum.serverless.com/t/file-foo-ts-is-not-under-rootdir-rootdir-is-expected-to-contain-all-source-files/9669/6 "2020-01-28T09:54:48Z")

</div>

What do you mean by “solution for external dependencies” @cgrafton ? One of main features of Lerna is handling internal modules dependencies. [https://github.com/lerna/lerna#about](https://github.com/lerna/lerna#about)

---

<div class="post-metadata">

**Author:** ![stanyq4](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/stanyq4/32/4755_2.png) [@stanyq4](https://forum.serverless.com/u/stanyq4)\
**Post date:** [November 22, 2020, 5:12pm UTC](https://forum.serverless.com/t/file-foo-ts-is-not-under-rootdir-rootdir-is-expected-to-contain-all-source-files/9669/7 "2020-11-22T17:12:29Z")

</div>

Have you succeeded with Option 2 - Utilize Webpack to allow setting the rootDir in typescript ?  
Or maybe have an example?  
Thank you!
