storybookjs / storybook

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation
https://storybook.js.org
MIT License
83.4k stars 9.12k forks source link

[Bug]: Cannot read properties of undefined (reading 'custom') in Next.js project #21911

Open yannbf opened 1 year ago

yannbf commented 1 year ago

Describe the bug

The issue started in https://github.com/storybookjs/storybook/releases/tag/v7.0.0-beta.29 and I suspect it might be related to https://github.com/storybookjs/storybook/pull/20615

image

To Reproduce

Check https://github.com/storybookjs/status-page Go to feat/upgrade-storybook

This has a workaround

The way to work around this issue is to customize webpack to mock out assert:

import type { StorybookConfig } from '@storybook/nextjs';
const config: StorybookConfig = {
  // ...
  webpackFinal: async (config) => {
    config.resolve = config.resolve || {};
    config.resolve.alias = {
      ...config.resolve.alias,
      // Mock assert to avoid issues like Cannot read properties of undefined (reading 'custom')
      assert: false,
    };
    return config;
  },
};
export default config;

System

No response

Additional context

No response

gitstart-app[bot] commented 1 year ago

Here is the GitStart Ticket for this issue: https://clients.gitstart.com/storybook-oss/1/tickets/STORYBOOK-21911

gitstart-storybook commented 1 year ago

@yannbf

Fouzyyyy commented 1 year ago

Hi,

Is there a workaround in the meantime?

vinnycodes commented 10 months ago

Having the same issue.

Considered that it may be our stories that could be causing this issue so removed all of our older stories and tried a fresh build with nextjs13. Issue continued and we cannot seem to find what could be causing this issue.

strmer15 commented 10 months ago

For me, adding in a resolve.alias into the webpack config fixed this:

    resolve: {
      ...config.resolve,
      alias: {
        ...config.resolve.alias,
        'assert': require.resolve('browser-assert'),
      },
    },
vinnycodes commented 10 months ago

For me, adding in a resolve.alias into the webpack config fixed this:

    resolve: {
      ...config.resolve,
      alias: {
        ...config.resolve.alias,
        'assert': require.resolve('browser-assert'),
      },
    },

Thank you so much! This is exactly what we needed. Any idea what could be causing this?

strmer15 commented 10 months ago

Thank you so much! This is exactly what we needed. Any idea what could be causing this?

For whatever package manager you're using, it's pulling in the actual assert package instead of the browser-assert package that is supposed to be used instead, via the fallback config in Storybook. See the post above at https://github.com/storybookjs/storybook/issues/21911#issuecomment-1589741323