Skip to content

fix(install): link bit's compiled core aspects into bit-roots instead of uncompiled source#10481

Closed
davidfirst wants to merge 2 commits into
masterfrom
fix/link-core-aspects-in-bit-roots
Closed

fix(install): link bit's compiled core aspects into bit-roots instead of uncompiled source#10481
davidfirst wants to merge 2 commits into
masterfrom
fix/link-core-aspects-in-bit-roots

Conversation

@davidfirst

Copy link
Copy Markdown
Member

Problem

When a workspace loads envs from root node_modules (resolveEnvsFromRoots: true), an env's constructor eagerly requires Bit core aspects (@teambit/builder, @teambit/ui, @teambit/pkg, …). In a workspace that authors those core aspects — the Bit repo itself — the bit-roots install injects them as workspace:*, i.e. the uncompiled source component, which has no dist/ during bit install (before bit compile). Result: Cannot find module '.../@teambit/builder/dist/index.js' and the install crashes.

Scope-aspects capsules don't hit this: they link Bit's own compiled core aspects (IsolatorMain.relinkCoreAspectsInCapsuleDirdependency-linker.linkCoreAspect, which resolves from Bit's install). The bit-roots path never did — getWorkspaceDepsOfBitRoots maps every workspace component (including core aspects) to workspace:*, and filterOutCoreAspects only covers the root policy, not this path.

Fix

Make bit-roots mirror capsules, entirely in the install/resolution layer:

  1. _omitCoreAspects strips core-aspect packages from the workspace:* deps injected into bit-roots.
  2. Filter the same packages out of linkPkgsToRootComponents (no source hard-link).
  3. _linkCoreAspectsToBitRoots links Bit's own compiled core aspects into each bit-root, reusing the exact linker path capsules use.

Blast radius

All three key off coreAspectPackageNames ∩ workspaceComponents, which is empty for any workspace that doesn't author Bit's core aspects — i.e. every normal user workspace. So it's a provable no-op for users and only changes behavior in the Bit repo. No change to the shared require hook.

Why

Unblocks resolveEnvsFromRoots: true in the Bit repo (envs load from node_modules instead of stacking per-version scope-aspects capsules in the global cache). The flag flip is a follow-up, after this ships in a nightly — the crash occurs inside the released bbit during setup_harmony, so it must land here first.

@davidfirst

Copy link
Copy Markdown
Member Author

Closing: empirically proven not to work.

Tested by patching bvm's install.main.runtime.js with this fix's compiled output and running bbit install against a reproduced fresh-checkout state (builder dist removed, resolveEnvsFromRoots: true). Result: identical crash to the unpatched control.

Root cause of the failure: Node resolves the env's symlink to its realpath in .pnpm/, then walks up .pnpm/<env>/node_modules/.pnpm/ → the workspace root node_modules/@teambit/builder (uncompiled). .bit_roots/<env>/node_modules/ — where this PR links the compiled core aspects — is never consulted. The linking ran correctly; it just targeted a directory node never looks at.

This is also why scope-aspects capsules work: the env's realpath is inside the capsule, so the walk-up finds the capsule's linked compiled core aspects.

Superseded by the require-hook approach (#10479), which is location-independent and is verified to work: full install + compile of 313 components on the same reproduced fresh state.

@davidfirst davidfirst closed this Jul 14, 2026
@davidfirst davidfirst deleted the fix/link-core-aspects-in-bit-roots branch July 14, 2026 21:26
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