Skip to content

fix(nx): stop the root project re-invoking nx, which raced docs-site against itself - #697

Merged
thinkclay merged 1 commit into
mainfrom
fix/693-nx-root-build-recursion
Sep 2, 2026
Merged

thinkclay merged 1 commit into
mainfrom
fix/693-nx-root-build-recursion

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Lint, typecheck & build has been red on main with two failed tasks:

- docs-site:build
- scaffald:build

They are one bug, and it is not in either docs site.

scaffald is the workspace root, and it is a real nx project. project.json
already neutralises lint, test and typecheck with echo no-ops so the root
does not recurse — but build was never given the same treatment. With no
build target declared, nx infers one from the root package.json script:

"build": "pnpm locales:validate && nx run-many -t build --exclude=@scaffald/ui-docs,scaffald"

So CI's nx run-many -t build schedules 10 projects, one of which shells out to
a second nx run-many -t build over 8 of the same projects. Both nx runs build
docs-site into the same directory at the same time. Whichever one is mid-SSG
when the other clears build/ fails on the artifact it was about to read:

ENOENT: no such file or directory,
  open 'packages/sdk/docs-site/build/__server/server.bundle.js'

The evidence it is a race rather than a config problem is in the CI log itself —
one run contains BOTH outcomes for the same task, plus nx's own verdict:

##[group]✅ > nx run docs-site:build     [SUCCESS] Generated static files
NX   Nx detected a flaky task
##[group]❌ > nx run docs-site:build     ENOENT … server.bundle.js

docs-site builds cleanly on its own, on a clean tree, with future.v4: true
left exactly as it is.

This adds the missing build no-op, matching the three targets beside it. The
nested nx run-many disappears, docs-site:build runs once instead of twice,
and every one of the 10 projects still builds — both docs sites still emit their
build/index.html. Verified before and after on a cold cache (nx reset); the
build log drops from 445 lines to 185 because half of it was the duplicate run.

Two notes for whoever reads this next:

  • pnpm build is untouched. Only the nx target for the root project changed;
    the npm script is still there and still works as a developer alias.
  • locales:validate no longer runs as part of the build target, but it has not
    been lost — pnpm check runs it first, in the same job, before lint.

A first pass at this blamed future.v4: true in the sdk docs config, because
flipping that flag to false does make the failure go away. That was a red
herring: v4 is simply what makes docusaurus route SSG through
build/__server/server.bundle.js, so turning it off hides the race instead of
fixing it. Left enabled on purpose.

Closes #693

🤖 Generated with Claude Code

…against itself

`Lint, typecheck & build` has been red on main with two failed tasks:

    - docs-site:build
    - scaffald:build

They are one bug, and it is not in either docs site.

`scaffald` is the workspace root, and it is a real nx project. `project.json`
already neutralises `lint`, `test` and `typecheck` with echo no-ops so the root
does not recurse — but `build` was never given the same treatment. With no
`build` target declared, nx infers one from the root `package.json` script:

    "build": "pnpm locales:validate && nx run-many -t build --exclude=@scaffald/ui-docs,scaffald"

So CI's `nx run-many -t build` schedules 10 projects, one of which shells out to
a second `nx run-many -t build` over 8 of the same projects. Both nx runs build
`docs-site` into the same directory at the same time. Whichever one is mid-SSG
when the other clears `build/` fails on the artifact it was about to read:

    ENOENT: no such file or directory,
      open 'packages/sdk/docs-site/build/__server/server.bundle.js'

The evidence it is a race rather than a config problem is in the CI log itself —
one run contains BOTH outcomes for the same task, plus nx's own verdict:

    ##[group]✅ > nx run docs-site:build     [SUCCESS] Generated static files
    NX   Nx detected a flaky task
    ##[group]❌ > nx run docs-site:build     ENOENT … server.bundle.js

`docs-site` builds cleanly on its own, on a clean tree, with `future.v4: true`
left exactly as it is.

This adds the missing `build` no-op, matching the three targets beside it. The
nested `nx run-many` disappears, `docs-site:build` runs once instead of twice,
and every one of the 10 projects still builds — both docs sites still emit their
`build/index.html`. Verified before and after on a cold cache (`nx reset`); the
build log drops from 445 lines to 185 because half of it was the duplicate run.

Two notes for whoever reads this next:

* `pnpm build` is untouched. Only the nx *target* for the root project changed;
  the npm script is still there and still works as a developer alias.
* `locales:validate` no longer runs as part of the build target, but it has not
  been lost — `pnpm check` runs it first, in the same job, before lint.

A first pass at this blamed `future.v4: true` in the sdk docs config, because
flipping that flag to false does make the failure go away. That was a red
herring: v4 is simply what makes docusaurus route SSG through
`build/__server/server.bundle.js`, so turning it off hides the race instead of
fixing it. Left enabled on purpose.

Closes #693

Co-Authored-By: Claude Opus 5 <[email protected]>
@thinkclay
thinkclay merged commit d23d443 into main Sep 2, 2026
7 checks passed
@thinkclay
thinkclay deleted the fix/693-nx-root-build-recursion branch September 2, 2026 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI: the workspace root re-invokes nx, racing docs-site:build against itself

1 participant