reactjstypescriptreact-nativestorybookturborepo

Storybook colocating stories in turbo repo package story not found


You can find the code to reproduce this issue here.

I am trying to add storybook to my turbo repo monorepo for my UI library. I am using story book react-native-web-vite as my renderer. However, when referencing stories outside of storybook app as shown in the turborepo docs I get an error:

Error

This error is not present in my terminal just the ui. Using the glob npm package I have verified all paths are correct and even tried absolute paths. Here is my main.ts file:

import {join, dirname} from "path";
import type {StorybookConfig} from "@storybook/react-native-web-vite";
import {createRequire} from "module";

const require = createRequire(import.meta.url);

/**
 * This function is used to resolve the absolute path of a package.
 * It is needed in projects that use Yarn PnP or are set up within a monorepo.
 */
function getAbsolutePath(value) {
  return dirname(require.resolve(join(value, "package.json")));
}

const config: StorybookConfig = {
  stories: ["../../../packages/ui/src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
  addons: [
    getAbsolutePath("@chromatic-com/storybook"),
    getAbsolutePath("@storybook/addon-vitest"),
  ],
  framework: {
    name: getAbsolutePath("@storybook/react-native-web-vite"),
    options: {},
  },
};
export default config;

Other than that my configuration is normal. Here is my story file:

import {Meta} from "@storybook/react-native-web-vite";
import Button from "../Button";

const meta: Meta<typeof Button> = {
  title: "Button",
  component: Button,
};

export default meta;

Here is the output from the sb info command:

  System:
    OS: macOS 15.5
    CPU: (12) arm64 Apple M2 Max
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.4.0 - ~/.nvm/versions/node/v23.4.0/bin/node
    npm: 11.4.2 - ~/.nvm/versions/node/v23.4.0/bin/npm
    pnpm: 10.12.1 - ~/Library/pnpm/pnpm <----- active
  Browsers:
    Safari: 18.5
  npmPackages:
    @storybook/addon-a11y: ^9.0.11 => 9.0.11
    @storybook/addon-docs: ^9.0.11 => 9.0.11
    @storybook/addon-onboarding: ^9.0.11 => 9.0.11
    @storybook/addon-vitest: ^9.0.11 => 9.0.11
    @storybook/react-native-web-vite: ^9.0.11 => 9.0.11
    storybook: ^9.0.11 => 9.0.11

Solution

  • The problem was that I was not exporting a story. I was only exporting meta. So instead of

    import {Meta} from "@storybook/react-native-web-vite";
    import Button from "../Button";
    
    const meta: Meta<typeof Button> = {
      title: "Button",
      component: Button,
    };
    
    export default meta;
    

    It should instead be:

    import {Meta} from "@storybook/react-native-web-vite";
    import Button from "../Button";
    
    const meta: Meta<typeof Button> = {
      title: "Button",
      component: Button,
    };
    
    export default meta;
    
    type Story = StoryObj<typeof meta>;
    
    export const Default: Story = {};