Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: react-docgen-typescript does not show props of components imported from node_modules #220

Open
hieu79115 opened this issue Jan 17, 2025 · 3 comments
Labels
need reproduction A minimal reproduction is needed to troubleshoot the issue.

Comments

@hieu79115
Copy link

Version

System:
    OS: Windows 11 10.0.22631
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
    Memory: 20.34 GB / 39.73 GB
  Browsers:
    Edge: Chromium (131.0.2903.99)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    storybook-react-rsbuild: ^0.1.8

Details

When using webpack (@storybook/react-webpack5), it worked as expected, after change to rspack (storybook-react-rsbuild), the typescript props do not show anymore
Before:
Image

After - using rspack:
Image

Thank you so much.

Reproduce link

none

Reproduce Steps

execute "yarn storybook"

@fi3ework
Copy link
Member

Please provide a minimal reproduction to help us address the issue, we cannot assist with troubleshooting based on the information currently provided.
Thanks.

Why reproduction is required

@fi3ework fi3ework added the need reproduction A minimal reproduction is needed to troubleshoot the issue. label Jan 17, 2025
@hieu79115
Copy link
Author

hieu79115 commented Jan 20, 2025

Hi @fi3ework , this is my .storybook/main.ts

import { StorybookConfig } from 'storybook-react-rsbuild'

import path, { join, dirname } from 'path';
import { pluginReact } from '@rsbuild/plugin-react';
import { pluginSass } from '@rsbuild/plugin-sass';

/**
 * 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: string): any {
  return dirname(require.resolve(join(value, 'package.json')));
}

const config: StorybookConfig = {
  stories: ['../src/stories/Configure.mdx', '../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx|mdx)'],
  addons: [
    getAbsolutePath('@storybook/preset-create-react-app'),
    getAbsolutePath('@storybook/addon-onboarding'),
    getAbsolutePath('@storybook/addon-links'),
    getAbsolutePath('@storybook/addon-essentials'),
    getAbsolutePath('@storybook/addon-controls'),
    getAbsolutePath('@storybook/addon-designs')
  ],
  framework: {
    name: getAbsolutePath('storybook-react-rsbuild'),
    options: {},
  },
  staticDirs: [path.resolve(__dirname, '../public')],
  typescript: {
    reactDocgen: 'react-docgen-typescript', // This is important for the addon to work with TypeScript
    reactDocgenTypescriptOptions: {
      shouldExtractLiteralValuesFromEnum: true,
      shouldRemoveUndefinedFromOptional: true,
    }
  },
  rsbuildFinal: async (config) => {
    config.resolve = {
      extensions: ['.ts', '.tsx', '.js', '.jsx', '.mdx'], // Support these file types
      alias: {
        components: path.resolve(__dirname, '../src/components'),
        pages: path.resolve(__dirname, '../src/pages'),
        models: path.resolve(__dirname, '../src/models'),
        hooks: path.resolve(__dirname, '../src/hooks'),
        utils: path.resolve(__dirname, '../src/utils'),
        src: path.resolve(__dirname, '../src'),
      },
    };
    config.plugins = [pluginReact(), pluginSass()];

    return config;
  },
};

export default config;

and this is using storybook-webpack-5 before

import type { StorybookConfig } from '@storybook/react-webpack5';
import path, { join, dirname } from 'path';

function getAbsolutePath(value: string): any {
  return dirname(require.resolve(join(value, 'package.json')));
}

const config: StorybookConfig = {
  stories: ['../src/stories/Configure.mdx', '../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx|mdx)'],
  addons: [
    getAbsolutePath('@storybook/preset-create-react-app'),
    getAbsolutePath('@storybook/addon-onboarding'),
    getAbsolutePath('@storybook/addon-links'),
    getAbsolutePath('@storybook/addon-essentials'),
    // getAbsolutePath('@chromatic-com/storybook'),
    // getAbsolutePath('@storybook/addon-interactions'),
    getAbsolutePath('@storybook/addon-controls'),
    getAbsolutePath('@storybook/addon-designs')
  ],
  framework: {
    name: getAbsolutePath('@storybook/react-webpack5'),
    options: {},
  },
  staticDirs: [path.resolve(__dirname, '../public')],
  swc: (config)=> {
    return {
      ...config,
    };
  },
  webpackFinal: async (config) => {
    if (config.module?.rules) {
      config.module.rules.push({
        test: /\.(ts|tsx)$/,
        use: [
          {
            loader: require.resolve('ts-loader'),
          },
        ],
      });
    }
    if (config.resolve?.extensions)
      config.resolve.extensions.push('.ts', '.tsx');
    if (config.resolve?.alias)
      config.resolve.alias = {
        ...config.resolve.alias,
      };
    if (config.output) {
      config.output.filename = '[name].[contenthash].js';
      config.output.chunkFilename = '[name].[contenthash].js';
    }
    return config;
  },
  typescript: {
    reactDocgen: 'react-docgen-typescript', // This is important for the addon to work with TypeScript
    reactDocgenTypescriptOptions: {
      shouldExtractLiteralValuesFromEnum: true,
      shouldRemoveUndefinedFromOptional: true,
    }
  },
};
export default config;

@fi3ework
Copy link
Member

fi3ework commented Jan 20, 2025

Would you please provide a minimal repository instead of some code snippets, it's hard to reproduce the issue only with some snippets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need reproduction A minimal reproduction is needed to troubleshoot the issue.
Projects
None yet
Development

No branches or pull requests

2 participants