Skip to content

[Bug]: Autodocs not working with react-native-web #24689

@simonadenic

Description

@simonadenic

Describe the bug

  • I have searched other issues

Overview

Im running Storybook for React, initialized with npx storybook@latest (storybook version 7.5.2). I added support for showing React Native components in this app by extending the SB configuration with @storybook/addon-react-native-web (version 0.0.21).
Components previews (examples) work fine, but when I add tags:['autodocs'], the Documentation preview fails with the following error:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.

Check the render method of `ArgsTable`.

Screenshot 2023-11-02 at 17 38 23

Component and story

Simple Button component:

// Button.tsx
import React from 'react';
import { TouchableOpacity, Text } from 'react-native';

export const Button = ({title, onPress}: {title: string; onPress: ()=>void}) => {
    return <TouchableOpacity onPress={onPress}>
        <Text>{title}</Text>
    </TouchableOpacity>

}

Simple Button story:

// Button.stories.ts
import { Button } from './Button';
const meta = {
  title: 'Mobile/MyButton',
  component: Button,
  // When this is deleted, everything works fine
  tags:['autodocs'] 
 
};
export default meta;

export const Primary = {
  args: {
    title: 'Primary text',
    onPress: () => {
      console.log('aaa');
    },
  },
};

export const Secondary = {
  args: {
    title: 'Secondary text',
  },
};

Storybook configuration

// main.ts
import { join, dirname } from 'path';
import {} from '@storybook/react';

/**
 * 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')));
}

/** @type { import('@storybook/react-webpack5').StorybookConfig } */
const config = {
  stories: [
    '../../../packages/components/**/*.mdx',
    '../../../packages/components/**/*.stories.@(js|jsx|mjs|ts|tsx)',
  ],
  addons: [
    getAbsolutePath('@storybook/addon-links'),
    getAbsolutePath('@storybook/addon-essentials'),
    getAbsolutePath('@storybook/addon-onboarding'),
    getAbsolutePath('@storybook/addon-interactions'),
    getAbsolutePath('@storybook/addon-react-native-web')   
  ],
  framework: {
    name: getAbsolutePath('@storybook/react-webpack5'),
    options: {},
  },
  typescript: { reactDocgen: false },
  docs: {
    autodocs: 'tag',
  },
};
export default config;

Console output

Console shows that the error is probably located in the storybook-addon-docs
Screenshot 2023-11-02 at 18 01 37

To Reproduce

  1. Clone the Github repository
  2. Run npm install
  3. Run npm run storybook

System

System:
OS: macOS 13.1
CPU: (10) arm64 Apple M1 Max
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.17.1 - ~/.nvm/versions/node/v18.17.1/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 9.6.7 - ~/.nvm/versions/node/v18.17.1/bin/npm <----- active
pnpm: 8.6.1 - ~/Library/pnpm/pnpm
Browsers:
Chrome: 119.0.6045.105
Safari: 16.2
npmPackages:
@storybook/addon-react-native-web: ^0.0.21 => 0.0.21

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions