Skip to main content

Command Palette

Search for a command to run...

Switching from Nx to Turborepo for Easier Shared Package Setup

Updated
2 min read

Both Nx and Turborepo provide a monorepo structure and good performance for managing multiple services.

While setting up my project with Nx, I ran into several issues related to build configuration and importing shared modules. Because of that friction, I decided to try Turborepo. For my use case, the setup felt simpler and the builds seemed faster.

One thing that was especially easier in Turborepo was creating a global shared package that multiple services can use.

Step 1 — Configure the shared package

Inside the shared folder, create a package.json like this:

{
  "name": "@repo/shared",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "build": "tsc",
    "dev": "tsc -w",
    "lint": "eslint . --max-warnings 0"
  },
  "exports": {
    ".": {
      "types": "./src/index.d.ts",
      "default": "./dist/index.js"
    }
  },
  "devDependencies": {
    "typescript": "^5.0.0",
    "@repo/eslint-config": "*",
    "@repo/typescript-config": "*"
  }
}

Step 2 — Create an index file

Create an index.ts file in the shared package and export everything you want other services to use.

Example:

export * from "./middlewares";
export * from "./utils";

Step 3 — Use the shared package in any service

Inside the service’s package.json, add:

"dependencies": {
  "@repo/shared": "*"
}

After installing dependencies, the shared package becomes available to import:

import { something } from "@repo/shared";

That’s it. Now the shared code can be reused across services.

For my current learning setup, this approach felt simpler and faster to configure compared to my earlier Nx setup.