Using Nub with Turborepo
Run Turborepo on top of Nub in a monorepo, with TypeScript and env files working inside every task. Keep your package manager for installs, or switch the repo to Nub and Turborepo runs every task with nub run.
Turborepo schedules and caches tasks across your packages; Nub provisions Node and augments the Node each task runs. You keep your Turborepo setup and launch it through Nub.
Setup
Run Turborepo through Nub, from a root script or with nubx:
nub run build # a root script: "turbo run build"
nubx turbo run build # or run turbo directly through nubxInstalls
For each package that defines a task, Turborepo spawns the repo's package manager with run <task>. It picks the manager from the packageManager field and the lockfile, so in a pnpm repo every task is pnpm run build.
That manager expects the node_modules tree it built. nub install reads and writes the same lockfile but lays node_modules out its own way, under node_modules/.store where pnpm uses node_modules/.pnpm, and pnpm can refuse to run scripts against a tree it didn't build. So choose one:
Keep your package manager for installs, and run Turborepo under Nub:
pnpm install
nub run buildSwitch the repo to Nub. Turborepo 2.10.3 and later detect the pin that nub pm use nub writes, and run each task as nub run <task>:
nub pm use nub # moves pnpm-workspace.yaml config, renames the lockfile
nub install
nub run buildnub pm use nub moves the pnpm-workspace.yaml settings into package.json, renames the lockfile to nub.lock, and pins Nub in devEngines.packageManager. Real pnpm then refuses to run in the repo, and nub pm use pnpm reverses the switch. See nub pm use.
TypeScript inside tasks
The package manager Turborepo spawns inherits Turborepo's environment. When Turborepo runs under Nub, that environment carries Nub's augmentation, a NODE_OPTIONS preload and a node shim on the PATH. So the node a task's script invokes is Nub's augmented Node.
A build script of plain node ./build.ts then runs TypeScript directly and loads that package's .env, with no per-package configuration:
// packages/lib/package.json
{
"name": "@acme/lib",
"scripts": { "build": "node ./build.ts" }
}// turbo.json
{
"tasks": { "build": {} }
}nub run build # root script: "turbo run build"@acme/lib:build: cache miss, executing
@acme/lib:build: [lib] built ok
Tasks: 1 successful, 1 totalLaunch Turborepo through Nub
A turbo run started from a plain shell runs tasks on the node on your PATH with no augmentation, and a .ts entry fails to parse. Keep the entry point a nub run script or nubx turbo so every run goes through Nub.
Node version
Nub provisions the Node your project pins, so every task in the monorepo runs on the same version without nvm or Corepack. Pin it with .node-version, .nvmrc, devEngines.runtime, or nub node pin. The package manager Turborepo spawns runs on that Node too, not an older one it finds on the PATH.
Caching and env files
Turborepo owns the task graph, scheduling, and caching. Nub owns the runtime and env loading under each task.
- Cache keys — Turborepo passes
NODE_OPTIONSthrough to tasks without hashing it, so adopting Nub does not invalidate your cache. - Env files — each task loads the
.envfor the package it runs in. Turborepo'senvandglobalEnvstill control cache hashing, so a value that must affect the cache still belongs inturbo.json.
Running NestJS with Nub
Run a NestJS application on Nub with no build step, including the decorator metadata Nest depends on and the Nest CLI plugins you give up.
Nub vs Vite+
Where Nub and Vite Plus overlap and where they differ. Nub is a package manager and runtime layer on stock Node; Vite Plus is an integrated frontend toolchain.