Just trying our hand at …

3 minute read

Just trying our hand at MonoRepo. Just investigating Nx as a fit for us. All cards on the table it looks like either Nx or Lerna. Our current repos (which will be merged into one) will consist of: • ReactJS frontend sites + Serverless Framework (Infrastructure) • Serverless Framework Infrastructure • React Components • NPM Modules Since we already have existing repos, with our own prettier, jest etc tests (we dont use TS) not sure how to start to assess Nx. Also would love to know how to create a logical dependency (frontend site that has dep on API endpoint of another project)


Here’s an article by Victor Savkin comparing Lerna and Nx. He’s obviously biased, but I think he made a fair comparison.


Manually defined dependencies are called implicitDependencies in nx.json. In this example, the client-e2e project has an implicit dependency on the client project.

"client-e2e": { "tags": ["scope:client"], "implicitDependencies": ["client"] },

To start evaluating, I would go through the free course (https://www.youtube.com/playlist?list=PLakNactNC1dH38AfqmwabvOszDmKriGco) to get comfortable with Nx

Then when you’re moving your code into the monorepo, I would start with putting one of your repos all in a single app. Make sure everything works. Then add a second a repo as a separate app. Make sure everything works. Then start breaking out reusable pieces of code into their own libraries.

Thanks! Much appreciated for the push in the right direction. Going to review all these.

If I understand correctly your last, yer saying to just pull our repos in one at a time? Thats essentially what I plan to do. It’s just that we already have one monorepo in that its 4 pieces of serverless infrastructure that is in dev and so far we have been manually deploying and managing dependencies… so I think it makes a good case to try with Nx. In this case though…. there is no frontend at all.

so setup…. will require Nx have some manual way to setup deps and implicitdeps.

Yes, that is good use case. Yes, you can define the implicit dependencies in nx.json. I assume the serverless functions are written in Node. In which case, you can just npm install @nrwl/node in your Nx repo and then run nx g @nrwl/node:app to create each of your separate pieces.

It’s generally easier to let nx create the config for you, then copy in your code and tweak the config to what you want

what suggested last is what we did at Trellis. We had our 2 repos (api and client) and generated a new Nx workspace then moved them in and changed configs as needed. We had some issues cause we were on karma before and had some issues getting jest running but figured it out in the end. You are already on jest so you will be able to update the nx generated jest configs with your prior values.

I know there was someone here that posted an Nx plugin for deploying to serverless/generating serverless apps through nx

Thanks. I’ll try to search for that plugin… but feel free to share if you remember where you saw it.

I believe it is int he <#CRXERGDA9 npm-packages> channel here!

Thanks! found it I think …https://nrwlcommunity.slack.com/archives/CRXERGDA9/p1576824359001200


I feel like I’m missing something obvious…. I followed your getting started and I’m getting zsh: command not found: nx

should I be globally installing nx?

isnt it needed as part of builds/deploys?

it is not my package so unfortunately I cannot be of much help! haven’t used it yet.

Sorry I should have said. “the getting started for Nx”. And its the Nx cli I’m referring to I think.

I just installed it globally.

Ah ok! that makes more sense, ya i normally have it installed globally but you can also instal it in your package json and then reference via yarn nx and that will use your local version of it.