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
- Set the step
working-directoryto the repository root that holdsnx.json. - Confirm
nx.jsonis present withls nx.json. - 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.jsonis present as an early CI step.
Related guides
Nx "Failed to process project graph" in CIFix Nx "Failed to process project graph" in CI - Nx could not build the project graph because a config file,…
Nx "Cannot find configuration for task" in CIFix Nx "Cannot find configuration for task" in CI. The project has no target with that name, or a stale proje…
Rush "rush.json config file was not found" in CIFix Rush "Unable to find rush.json configuration file" in CI - Rush walked up from the working directory and…