storybook: Storybook and angular library: Cannot read property 'selector' of undefined

Describe the bug Added story within component folder for Angular 13.2.5 component library, while using storybook, it shows me the error as below:

Cannot read properties of undefined (reading 'selector')

To Reproduce

System Environment Info:

System: OS: Windows 10 10.0.19044 CPU: (4) x64 Intel® Core™ i7-7500U CPU @ 2.70GHz Binaries: Node: 16.14.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.19.1 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 8.3.1 - C:\Program Files\nodejs\npm.CMD Browsers: Chrome: 98.0.4758.102 Edge: Spartan (44.19041.1266.0), Chromium (98.0.1108.62) npmPackages: @storybook/addon-actions: ^6.4.19 => 6.4.19 @storybook/addon-essentials: ^6.4.19 => 6.4.19 @storybook/addon-interactions: ^6.4.19 => 6.4.19 @storybook/addon-links: ^6.4.19 => 6.4.19 @storybook/angular: ^6.4.19 => 6.4.19 @storybook/builder-webpack5: ^6.4.19 => 6.4.19 @storybook/manager-webpack5: ^6.4.19 => 6.4.19 @storybook/testing-library: ^0.0.9 => 0.0.9

Additional context The stories are kept outside the .stories folder.

image

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 11
  • Comments: 16 (3 by maintainers)

Most upvoted comments

I got it to work by removing the node_modules folder from my Angular Library project.

I believe the issue was located here

export const getComponentDecoratorMetadata = (component: any): Component | undefined => {
  const decorators = reflectionCapabilities.annotations(component);

  return decorators.reverse().find((d) => d instanceof Component);
};

There are two Component decorators: one from my Angular Library project and the other from the top-level workspace. That’s why d instanceof Component evaluates to false.

I found that I have some dependencies (Style Dictionary + SVGO) installed within my Angular Library project, rather than the top-level workspace.

Moving these back to the workspace has fixed this issue for me.

Looks like the issue only happens on Windows, I ran the same code in Mac and it’s magically working.