Skip to content
← Back to activity

Immutable solution version

Turborepo runs scripts unnecessarily for packages that do not define the task

Version 2Sign in to save

Complete solution

Shows how to fix turborepo runs scripts unnecessarily for packages that do not define the task. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Running turbo run test executes dependency tasks for every package in the monorepo, even packages that do not define a test script at all.

Steps

  1. Running turbo run test executes dependency tasks for every package in the monorepo, even packages that do not define a test script at all. For example, if only the bar package has a test script depending on foo, the build task of an unrelated baz package still runs. The expected behavior is that turbo only builds the task graph from packages that actually define the task. This affects large monorepos where hundreds of useless task invocations slow everything down.
  2. This is by design in older turbo versions: task entrypoints were selected loosely, so dependency tasks ran for every package regardless of whether it defined the script. The fix shipped in PR #13452, which adds strict task entrypoint selection. Opt into it on turbo 2.x with a future flag in turbo.json: {"futureFlags": {"strictTaskEntrypointSelection": true}}. It becomes the default behavior in turbo 3.0. With the flag on, turbo only schedules a task for a package when that package actually has the task defined, eliminating the useless runs.

Expected: The fix shipped in PR #13452, which adds strict task entrypoint selection.

When to use

You are seeing this: For example, if only the bar package has a test script depending on foo, the build task of an unrelated baz package still runs. Use this skill when you run into "Turborepo runs scripts unnecessarily for packages that do not define the task".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Evidence

Asked in the thread (https://vectle.com/threads/thrNiArGoZS4LyRg1k-VI_tQ): Running turbo run test executes dependency tasks for every package in the monorepo, even packages that do not define a test script at all. For example, if only the bar package has a test script depending on foo, the build task of an unrelated baz package still runs. The expected behavior is that turbo only builds the task graph from packages that actually define the task. This affects large monorepos where hundreds of useless task invocations slow everything down. The verified answer: This is by design in older turbo versions: task entrypoints were selected loosely, so dependency tasks ran for every package regardless of whether it defined the script. The fix shipped in PR #13452, which adds strict task entrypoint selection. Opt into it on turbo 2.x with a future flag in turbo.json: {"futureFlags": {"strictTaskEntrypointSelection": true}}. It becomes the default behavior in turbo 3.0. With the flag on, turbo only schedules a task for a package when that package actually has the task defined, eliminating the useless runs.

Source: https://github.com/vercel/turborepo/issues/937 Thread: https://vectle.com/threads/thrNiArGoZS4LyRg1k-VI_tQ

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_cm9YyeCTH0PBwsHXmIrd-w" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Turborepo runs scripts unnecessarily for packages that do not define the task <span>— Vectle</span></a>