Skip to content

Resolve turbo through the root symlink so in-app updates use the newly installed version - #7312

Merged
ymichael merged 1 commit into
mainfrom
bb/fix-turbo-module-not-found-error-thr_x8ksjp5wyd
Nov 9, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/fix-turbo-module-not-found-error-thr_x8ksjp5wyd

Conversation

@ymichael

@ymichael ymichael commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

When a source checkout updates itself in the app, the scripts/start-bb.mjs process stays alive. Each update runs pnpm install and then rebuilds in that same process. buildRuntimeArtifacts found turbo with require.resolve("turbo/bin/turbo"). Node caches that result, with symlinks already followed, for as long as the process runs, and a fresh createRequire shares the same cache. So the process keeps handing the build the .pnpm/turbo@<version> path it saw at startup, even after updates move node_modules/turbo to a newer version.

For a while this does no harm. pnpm leaves the old version's folder on disk, and the old bin/turbo script hands off to the repo's local turbo, so builds still run the new version. pnpm deletes unused folders only once modules-cache-max-age (7 days) has passed since its last cleanup. When that cleanup runs during an update, the cached path points at a deleted file and the rebuild fails:

Error: Cannot find module '/Users/michael/Projects/bb/node_modules/.pnpm/[email protected]/node_modules/turbo/bin/turbo'
✗  Rebuilding bb 0.49.0 (f8893ee23c) failed: Runtime build failed with exit code 1

In the reported case, one process had run several updates since before #7133 (Nov 5) moved turbo from 2.10.12 to 2.11.10. The update that failed (55135d1e50 → f8893ee23c) didn't change turbo. It was the install where pnpm ran its cleanup (node_modules/.modules.yaml shows prunedAt: Mon, 09 Nov 2026 22:26:25 GMT, the time of the failed update).

What changed

scripts/start-bb.mjs now passes <repoRoot>/node_modules/turbo/bin/turbo, the symlink path, to the build child process instead of resolving it in the long-lived process. The child node follows the symlink when it starts, so each build runs the turbo installed at that moment. turbo is a root devDependency, so node_modules/turbo is always present at the root. The unused createRequire import is removed.

How you verified

Ran a real in-app update end to end, once with pre-fix code (control) and once with this PR (fix). Each run used a scratch clone, a local bare origin, its own data dir and ports, and bb updates app apply --yes:

  • Commit A pins turbo to 2.10.12, and origin/main is commit B, which reverts that pin back to ^2.11.10. Control is built on 7d57800665; fix is built on this PR's commit.
  • After pnpm install at A, prunedAt in node_modules/.modules.yaml was backdated 8 days, so pnpm's own cleanup runs during the update, as it did in the reported case.
  • Control: the shim logged - turbo 2.10.12 / + turbo 2.11.10, then Error: Cannot find module '.../.pnpm/[email protected]/node_modules/turbo/bin/turbo' and ✗ Rebuilding bb … failed: Runtime build failed with exit code 1. That is the reported failure.
  • Fix: same steps. The rebuild ran turbo 2.11.10, bb came back up, and bb updates app status reported source checkout cd48a0e87b is up to date.
  • Without the backdated prunedAt, the control also succeeds. A Module._findPath trace showed the shim reusing the cached [email protected] path on the second build; it worked because that folder still existed.
  • pnpm start --dryrun builds through the new path. pnpm exec turbo run test --filter=@bb/scripts -- test/start-bb.test.mjs passes 4/4.

AGENT GENERATED

🤖 Generated with Claude Code

…y installed version

The source update shim runs pnpm install and then rebuilds inside the
process that built at startup. require.resolve memoizes realpaths
process-wide, so after a turbo bump it returned the removed
.pnpm/turbo@<old> entrypoint and the rebuild failed with
MODULE_NOT_FOUND. Passing the node_modules/turbo symlink path lets the
child node process resolve it fresh.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit e17c36b into main Nov 9, 2026
53 checks passed
@ymichael
ymichael deleted the bb/fix-turbo-module-not-found-error-thr_x8ksjp5wyd branch November 9, 2026 22:56
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.

1 participant