Skip to content
Latchkey

Turborepo "root task ... must not depend on" in CI

Turborepo refuses a dependency on a root task (//#task) when that root task itself calls turbo, because the root package is a dependency of every package and the chain would recurse. Turbo blocks it rather than loop.

What this error means

A turbo run step fails with a message that a root task such as "//#build" looks like it invokes turbo and may cause a loop, or that the root task must not depend on another task.

Turbo
x root task //#build (turbo run build) looks like it invokes turbo and
  might cause a loop

Common causes

A root task that calls turbo

The root package.json script for the task runs turbo run ...; depending on //#task would re-enter Turbo from the root, which is every package's dependency.

Another task depends on the recursive root task

A dependsOn: ["//#build"] points at a root task that fans back into Turbo, so the engine rejects the graph.

How to fix it

Make the root task not invoke turbo

  1. Change the root task so its script does not call turbo (run the tool directly).
  2. Then it is safe to add the root task to tasks and depend on //#task.
  3. Re-run the pipeline.
package.json (root)
{
  "scripts": { "build": "tsc -b" }
}

Drop the dependency on the recursive root task

Remove the //#task entry from dependsOn if the root task must keep calling turbo, and orchestrate it from a separate command instead.

How to prevent it

  • Keep root tasks free of turbo run if other tasks depend on them.
  • Reserve //#task dependencies for leaf commands, not turbo wrappers.
  • Model fan-out with ^task dependencies rather than root tasks.

Frequently asked questions

What causes "Turbo "root task ... must not depend on""?
The root package.json script for the task runs turbo run ...; depending on //#task would re-enter Turbo from the root, which is every package's dependency.
How do I fix Turbo "root task ... must not depend on"?
Make the root task not invoke turbo

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card