How to deploy "nx" monorepos on Launch

  • 14 February 2024
  • 0 replies
  • 47 views

Problem Statement

Launch supports deploying monorepos. The documentation shows how to deploy monorepos using an Turborepo as the framework. nx is a similar monorepo framework. You might face issues deploying an nx based monorepo setup on Launch.

 

Root cause

By default, the nx outputs to a different dist directory, outside the source directory. This approach is different from other monorepos, notably turborepo, which outputs the build to the same source directory structure. For e.g. if we have the following directory structure for a NextJS based module in a monorepo:

/apps/myapp

By default, nx will output the build at:

/dist/apps/myapp/.next

While turborepo outputs at:

/apps/myapp/.next

Launch does not support outputing the build to a separate directory structure.

 

Steps to Resolve

  1. In the project.json file, change the outputPath from dist/apps/myapp to just apps/myapp

  2. In the environment settings, under "Deployment", change the following settings:

  3. Framework Preset: NextJs

  4. Output Directory: ./apps/myapp/.next

  5. Build Command:  npx nx build myapp

  6. Retrigger the deployment with the new  code.

Some things to keep in mind:

  • Burst nx cache before deploying the codebase (npx nx reset)

  • Remove the output directory before deploying the codebase (./apps/myapp/.next)


0 replies

Be the first to reply!

Reply