Skip to content

[Bug]: v9 cyclic dependency in storybook/preview causes metro to crash when react compiler is enabled #31573

@dannyhw

Description

@dannyhw

Describe the bug

the addon imports in src/shared/preview/core-annotations.ts result in a cyclic dependency after bundled since we end up with

storybook/preview-api -> storybook/measure -> storybook/preview-api

normally this wouldn't be an issue but there is currently a bug with metro which can cause crashes with cyclic dependencies.

so this is kinda a long winded issue but it would still be good to remove cyclic dependencies if possible

Reproduction link

https://github.com/dannyhw/repro-compiler

Reproduction steps

  1. clone the project
  2. bun install
  3. bun run storybook:ios

System

Storybook Environment Info:

  System:
    OS: macOS 15.5
    CPU: (10) arm64 Apple M1 Max
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.14.0 - /usr/local/bin/node
    Yarn: 1.22.22 - ~/Library/pnpm/yarn
    npm: 10.9.2 - /usr/local/bin/npm
    pnpm: 10.4.0 - ~/Library/pnpm/pnpm
  npmPackages:
    @storybook/addon-docs: 9.0.0-rc.4 => 9.0.0-rc.4 
    @storybook/addon-ondevice-actions: 9.0.0-rc.4 => 9.0.0-rc.4 
    @storybook/addon-ondevice-backgrounds: 9.0.0-rc.4 => 9.0.0-rc.4 
    @storybook/addon-ondevice-controls: 9.0.0-rc.4 => 9.0.0-rc.4 
    @storybook/addon-ondevice-notes: 9.0.0-rc.4 => 9.0.0-rc.4 
    @storybook/react: 9.0.0-rc.4 => 9.0.0-rc.4 
    @storybook/react-native: 9.0.0-rc.4 => 9.0.0-rc.4 
    @storybook/react-native-web-vite: 9.0.0-rc.4 => 9.0.0-rc.4 
    storybook: 9.0.0-rc.4 => 9.0.0-rc.4

Additional context

only happens if the react compiler is enabled for react native projects

heres the issue on react native storybook
storybookjs/react-native#732

a workaround is comment out these lines in node_modules/storybook/dist/preview-api/index.js for example with a package patch

// src/shared/preview/core-annotations.ts
// import ao from "storybook/internal/component-testing/preview";
// import lo from "storybook/actions/preview";
// import co from "storybook/backgrounds/preview";
// import po from "storybook/highlight/preview";
// import uo from "storybook/measure/preview";
// import fo from "storybook/outline/preview";
// import yo from "storybook/test/preview";
// import mo from "storybook/viewport/preview";
function Ie() {
  return [
    // @ts-expect-error CJS fallback
    // (uo.default ?? uo)(),
    // // @ts-expect-error CJS fallback
    // (co.default ?? co)(),
    // // @ts-expect-error CJS fallback
    // (po.default ?? po)(),
    // // @ts-expect-error CJS fallback
    // (fo.default ?? fo)(),
    // // @ts-expect-error CJS fallback
    // (mo.default ?? mo)(),
    // // @ts-expect-error CJS fallback
    // (lo.default ?? lo)(),
    // // @ts-expect-error CJS fallback
    // (ao.default ?? ao)(),
    // // @ts-expect-error CJS fallback
    // (yo.default ?? yo)(),
  ];
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions