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.
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?
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.
Utilize Webpack to allow setting the rootDir in typescript
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”:
`find microservices ! -path microservices -type d -maxdepth 1 -d -exec ln -s ../../_shared ./{} \;`
You'll then want to add each symlink to your .gitignore:
`/microservices/**/_shared`
So the workflow for the project is:
1.First time you clone the repo, run the bash script to create the symlinks
2. When you are in a microservices sub one level directory, reference imports from _shared
from the symlink on that same level
3. Make and commit all changes to the top level _shared directory
or 4. Use Lerna as 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