fix(preview): support generating preview for envs without a compiler#10406
Merged
Conversation
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
Contributor
There was a problem hiding this comment.
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 inComponentBundlingStrategy.getComponentOutputPath. - Ensures the preview link target directory exists before writing (prevents
ENOENTwhen 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. |
GiladShoham
approved these changes
Jun 8, 2026
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Running
bit buildon a component whose env has a bundler/preview but no compiler failed during theteambit.preview/preview:GeneratePreviewtask. An env without a compiler became possible a while back, but it was only tested with the preview disabled (e.g.EmptyEnve2e tests, where the env has no bundler so the preview task bails out early). When the preview is actually needed, two issues surfaced:context.env.getCompiler is not a function— the component bundling strategy calledgetCompiler()directly, unlike every sibling call site which already uses optional chaining.ENOENTwhen writing the preview link file — it targets the compiler'sdistdir, which a compiler-less env never creates.Fix
getCompiler()call inComponentBundlingStrategy.getComponentOutputPath, matching the other call sites.ensureDirSync(targetDir)before writing the preview link inwriteLinkContents, so a missing dist dir is created.Verified end-to-end: a component on a bundler-but-no-compiler env now builds through
GeneratePreviewandPreBundlePreviewsuccessfully.