Skip to content
Latchkey

Nx "Cannot find nx.json" / not an Nx workspace in CI

Nx resolves the workspace by walking up from the working directory until it finds nx.json. If the step runs in the wrong directory or the file is not in the checkout, Nx reports that this is not an Nx workspace.

What this error means

An Nx command fails with "Cannot find nx.json" or "The current directory isn't part of an Nx workspace" even though Nx is installed.

Nx
NX   Cannot find nx.json. Are you running this command inside an Nx workspace?

Common causes

The step runs from the wrong directory

The job changed into a subdirectory (or a different package) where Nx cannot find nx.json by walking up.

nx.json is not in the checkout

A sparse checkout or a misconfigured working directory left nx.json out of the files available to the runner.

How to fix it

Run from the workspace root

  1. Set the step working-directory to the repository root that holds nx.json.
  2. Confirm nx.json is present with ls nx.json.
  3. Re-run the Nx command from there.
.github/workflows/ci.yml
- run: nx affected -t build
  working-directory: ${{ github.workspace }}

Include nx.json in the checkout

If using a sparse checkout, make sure the root nx.json and package.json are part of the checked-out paths.

How to prevent it

  • Run Nx commands from the workspace root.
  • Avoid sparse checkouts that omit nx.json.
  • Verify nx.json is present as an early CI step.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →