You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React StoryBook动态组件失效问题:Next.js项目中FaqPage组件未在StoryBook中显示

Let's walk through the common issues that might be preventing your TestButton component from showing up in Storybook, and fix them one by one:

1. Verify Storybook's Story Detection Configuration

First, check your .storybook/main.js file to ensure it's configured to scan for your stories files. The stories array needs to include the path to your FaqPage.stories.js. For example:

module.exports = {
  stories: [
    "../**/*.stories.js", // Scans all .stories.js files across your project
    // Or use a more specific path like "../components/**/*.stories.js" if your files live in a components folder
  ],
  addons: [
    "@storybook/addon-links",
    "@storybook/addon-essentials",
    "@storybook/addon-interactions",
    "@storybook/nextjs",
  ],
  framework: {
    name: "@storybook/nextjs",
    options: {},
  },
};

If your stories file isn't covered by the path pattern here, Storybook won't find it. Adjust the pattern to match your project's folder structure.

2. Fix Import Path or Filename Issues

Double-check the import in FaqPage.stories.js:

import TestButton from './TestButton'
  • Confirm TestButton.js is in the exact same directory as FaqPage.stories.js (update the path if it's in a subfolder, e.g., ./ui/TestButton).
  • Ensure filenames match exactly (case-sensitive! On Linux/macOS, testbutton.js is not the same as TestButton.js).

3. Validate Story Export Structure

Your story setup is mostly correct, but let's confirm a few details:

  • Your default export (story metadata) has the required title and component fields, which is good—this will place your story under a "Button" category in the Storybook sidebar:
    const FaqPage = {
      title: 'Button',
      component: TestButton,
    }
    export default FaqPage
    
  • A minor note that won't break visibility but will fix styling: your primary arg is a string 'true' instead of a boolean true. Update it to:
    Index.args = {
      primary: true, // Use boolean instead of string
      label: 'Hello',
      backgroundColor: 'blue',
      size: 'medium',
    }
    

4. Check Terminal for Startup Errors

When you run npm run storybook (or yarn storybook), scan the terminal output for errors. Common culprits include:

  • Missing Next.js-specific Storybook dependencies
  • Syntax errors in TestButton.js or FaqPage.stories.js
  • Module resolution failures

Fix any errors you find—Storybook can fail to load stories if there's a foundational issue with your code or dependencies.

5. Refresh the Storybook Browser Tab

Sometimes Storybook doesn't auto-detect new stories immediately. Try refreshing http://localhost:6006 after making changes to your files or config.


After working through these steps, your TestButton story should appear in the Storybook sidebar under the "Button" section. If it still doesn't, double-check that all files are saved and your project structure aligns with Storybook's scanning rules.

内容的提问来源于stack exchange,提问作者Shruthi R

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 04:24:06