Skip to content

fix(preview): support generating preview for envs without a compiler#10406

Merged
davidfirst merged 4 commits into
masterfrom
fix-preview-env-without-compiler
Jun 8, 2026
Merged

fix(preview): support generating preview for envs without a compiler#10406
davidfirst merged 4 commits into
masterfrom
fix-preview-env-without-compiler

Conversation

@davidfirst

Copy link
Copy Markdown
Member

Problem

Running bit build on a component whose env has a bundler/preview but no compiler failed during the teambit.preview/preview:GeneratePreview task. An env without a compiler became possible a while back, but it was only tested with the preview disabled (e.g. EmptyEnv e2e tests, where the env has no bundler so the preview task bails out early). When the preview is actually needed, two issues surfaced:

  1. context.env.getCompiler is not a function — the component bundling strategy called getCompiler() directly, unlike every sibling call site which already uses optional chaining.
  2. After guarding that, ENOENT when writing the preview link file — it targets the compiler's dist dir, which a compiler-less env never creates.

Fix

  • Guard the getCompiler() call in ComponentBundlingStrategy.getComponentOutputPath, matching the other call sites.
  • ensureDirSync(targetDir) before writing the preview link in writeLinkContents, so a missing dist dir is created.

Verified end-to-end: a component on a bundler-but-no-compiler env now builds through GeneratePreview and PreBundlePreview successfully.

A compiler-less env (bundler/preview enabled but no compiler) failed during
the GeneratePreview build task with "context.env.getCompiler is not a function"
and, once that was guarded, with ENOENT when writing the preview link into a
non-existent dist dir.

- guard the getCompiler() call in the component bundling strategy
- ensure the target dir exists before writing the preview link contents
Copilot AI review requested due to automatic review settings June 8, 2026 14:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes preview generation for components whose env provides a bundler/preview pipeline but does not implement a compiler, allowing bit build to proceed through teambit.preview/preview:GeneratePreview without runtime failures.

Changes:

  • Avoids calling context.env.getCompiler() when the env doesn’t implement it by using optional chaining in ComponentBundlingStrategy.getComponentOutputPath.
  • Ensures the preview link target directory exists before writing (prevents ENOENT when the directory is normally created by a compiler).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
scopes/preview/preview/strategies/component-strategy.ts Guards compiler access when resolving the component output path for preview link generation.
scopes/preview/preview/preview.main.runtime.ts Creates the target directory before writing the generated preview link file to disk.

…piler

reproduces the scenario fixed in the previous commit: a component on an env
that has a preview/bundler but no compiler (like bitdev.general/envs/js-env).
adds a react-based env fixture with the compiler and build pipe removed.
Copilot AI review requested due to automatic review settings June 8, 2026 18:38
@davidfirst davidfirst enabled auto-merge (squash) June 8, 2026 18:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

@davidfirst davidfirst merged commit ece319f into master Jun 8, 2026
13 checks passed
@davidfirst davidfirst deleted the fix-preview-env-without-compiler branch June 8, 2026 19:18
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.

3 participants