Builder vs Framework Precedence in Storybook 7 – Which Setting Wins?
0 reputation · 22 Nov 2024, 13:56 UTC
0 reputation · 22 Nov 2024, 13:56 UTC
The framework key in main.js declares the UI framework (e.g., react, vue) and implicitly pulls in a compatible builder. The builder key can override that default, but the documentation marks it as deprecated and hints that the framework should be the source of truth.
When both keys are present, users report inconsistent behavior: some see the explicit builder win, others observe the framework’s default prevail, and in custom framework scenarios the builder property appears ignored unless framework is set to storybook. Add‑ons that require a specific builder also seem to influence the final selection.
Because the official docs do not state the exact precedence order and newer releases (e.g., 7.2+) may have altered the logic, the community lacks a definitive answer.
Questions to resolve the uncertainty:
builder: 'vite' always override the default builder provided by the framework, regardless of order?builder property ignored unless framework is set to storybook?framework and builder are defined?32775 reputation · 22 Nov 2024, 19:07 UTC
In Storybook 7, the framework key wins. A framework preset such as @storybook/react-vite or @storybook/react-webpack5 bundles both the renderer and the builder, so the builder is implied by the framework package you name. The top-level builder key is a deprecated legacy option; it is only honored in setups where no framework preset supplies a builder. When both are present and conflict, the framework's builder prevails.
The confusion usually comes from mixing a builder-specific framework package with a conflicting explicit key:
// .storybook/main.js
export default {
framework: '@storybook/react-vite', // hard-codes Vite
builder: 'webpack5', // deprecated, effectively ignored here
};Because @storybook/react-vite wires Vite into its own preset, builder: 'webpack5' cannot redirect it — the key appears to be silently ignored. Conversely, in older or zero-config setups without a builder-bearing framework preset, the explicit builder key is the only source and does take effect. That split explains the contradictory reports.
Caveat: exact fallback handling of a stray builder key varied across 7.x minor releases, and the key is removed entirely in Storybook 8. Treat any observed "explicit builder wins" behavior as version-specific, not contractual.
For a custom framework, the builder must come from the preset itself — the preset exports or references its builder via its options. Pointing framework at a custom preset that bundles no builder and expecting the top-level builder key to fill the gap is not a supported path in v7. If your custom preset needs Vite, wrap or extend an official Vite-based preset (e.g., re-export from @storybook/react-vite with your additions) rather than relying on the deprecated key.
No. Add-ons like @storybook/addon-essentials are largely builder-agnostic and do not participate in builder selection. Some add-ons ship builder-specific presets (for example, ones that alias webpack internals); those only fail or warn when the active builder mismatches — they never change which builder is chosen.
builder key from main.js/main.ts.@storybook/<renderer>-vite or @storybook/<renderer>-webpack5.npx storybook info, or start with DEBUG=storybook:* npx storybook dev and check the startup banner and debug output for the builder name.npm ls @storybook/core-server) before assuming any precedence behavior, and inspect the framework package's preset exports if results surprise you.This also removes a migration hazard, since the builder key does not exist in Storybook 8.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.