Nx is designed for incremental adoption. You can add it to any existing codebase with a single command and start with just task caching, then gradually add plugins, CI integrations, and distribution.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nrwl/nx/llms.txt
Use this file to discover all available pages before exploring further.
Add Nx to an existing project
Run the following command in the root of any existing project or monorepo:init command walks you through an interactive setup that:
- Detects your package manager and workspace structure
- Identifies existing scripts in
package.jsonfiles - Asks which scripts to cache and what their output directories are
- Creates
nx.jsonwith sensible defaults - Optionally connects to Nx Cloud for remote caching
What Nx detects and configures automatically
When you runnx init, Nx inspects your repository and configures:
Project discovery
Project discovery
Nx reads
package.json files across the workspace to discover projects and their names. If project.json files are present, those take precedence.Task configuration
Task configuration
Scripts defined in each
package.json become Nx tasks. Nx infers dependsOn relationships (for example, build depends on upstream build) from common patterns and from Nx plugin inference rules.Caching inputs and outputs
Caching inputs and outputs
Nx creates default
inputs (source files and package.json) and asks you to specify outputs (build directories) for each cacheable task during setup.Plugin inference
Plugin inference
If your projects use supported tools (Vite, Jest, ESLint, Playwright, etc.), the corresponding Nx plugin can be added to infer task configuration automatically — removing manual config duplication.
Migrating from specific tools
- Lerna
- Turborepo
- npm/pnpm/yarn workspaces
Lerna workspaces are npm/yarn workspaces underneath. Run:Nx detects the Nx affected is more accurate than Lerna’s
workspaces field in the root package.json and discovers all packages. Lerna’s lerna.json is not removed; Nx and Lerna can coexist, letting you migrate incrementally.To replace Lerna’s task orchestration with Nx:--since flag because it uses the full project dependency graph rather than file ownership alone.Incremental migration strategy
You don’t need to adopt every Nx feature at once.Start with caching only
Run
npx nx@latest init and answer the setup questions. You immediately get local task caching with no other changes to your workflow.Add remote caching
Run
npx nx@latest connect to link your workspace to Nx Cloud. Cache hits are now shared across your team and CI pipeline.Add plugins for your tech stack
Nx plugins for React, Angular, Node, Vite, Jest, and others can infer task configuration from existing tool config files — reducing the amount of configuration you manage manually.
Set up CI with affected commands
Update your CI pipeline to use
nx affected so only changed projects are tested and built on each pull request.Keeping Nx updated with nx migrate
Use nx migrate to update Nx and all @nx/* packages together. Never update them manually — version mismatches cause subtle errors.
Standard update process
Generate the migration plan
package.json and generates a migrations.json file listing the code migrations to apply. No files other than package.json are changed at this point.Apply code migrations
migrations.json, updating configuration files and source code to match the new versions. All changes are left unstaged for you to review.Updating community plugins
Community plugins are updated separately:Advanced migration options
| Flag | Purpose |
|---|---|
nx migrate latest --interactive | Prompt before applying optional package updates (e.g., skip a framework major version). |
nx migrate --run-migrations --create-commits | Create a separate git commit per migration for easier review. |
nx migrate latest --to="jest@29.0.0" | Override the version Nx would install for a specific package. |
nx migrate --run-migrations=migrations.json | Run migrations from a custom file path. |
