Nx affected: base SHA not found in CI (fetch-depth)
Nx affected diffs your branch against a base commit, but a shallow CI checkout did not fetch that commit, so the SHA is not in local history and the diff fails.
What this error means
nx affected fails resolving the base, with git complaining the base SHA is not a valid object or "fatal: bad object". The default actions/checkout fetch-depth of 1 is the usual cause.
nx
NX Unable to find base SHA "a1b2c3d" in the repository.
fatal: bad object a1b2c3dCommon causes
Shallow clone hides the base commit
actions/checkout defaults to fetch-depth 1, so the base SHA Nx needs for the diff is not present.
Base ref not fetched
The main branch or merge-base was never fetched, so there is nothing to diff against.
Wrong --base value
A --base pointing at a SHA or ref that does not exist in the checkout.
How to fix it
Fetch full history in checkout
- Set fetch-depth to 0 so the base commit is available.
workflow.yml
- uses: actions/checkout@v4
with:
fetch-depth: 0Use the Nx set-shas action
- Compute correct base and head SHAs for affected commands.
workflow.yml
- uses: nrwl/nx-set-shas@v4
- run: npx nx affected -t build --base=${NX_BASE} --head=${NX_HEAD}How to prevent it
- This is a common CI gotcha: nx affected needs git history, so always use fetch-depth 0 (or nx-set-shas) when computing affected projects.
Related guides
Nx "Failed to process project graph" in CIFix Nx "Failed to process project graph" in CI. A malformed project.json, a plugin error, or a circular depen…
Turborepo filter since-ref base not found in CIFix Turborepo --filter "[ref]" base errors in CI. A shallow clone means the comparison ref is missing, so tur…
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…