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]: Angular 19: Unexpected Component found in the "declarations" array of the "StorybookComponentModule" NgModule #29671

Closed
Eirmas opened this issue Nov 20, 2024 · 7 comments · Fixed by #29677

Comments

@Eirmas
Copy link

Eirmas commented Nov 20, 2024

Describe the bug

When creating a story for a standalone component in Angular 19, it fails because the renderer tries to create an NgModule with the standalone component in its declarations array. This causes an error because standalone components can't be declared in any NgModule.

Reproduction link

https://stackblitz.com/edit/github-kskywf?file=src%2Fstories%2Fbutton.stories.ts

Reproduction steps

  1. Update to angular 19
  2. Create a standalone angular component
  3. Create a story for this component like this:
export default {
  title: 'Title',
  component: MyComponent,
};

System

Storybook Environment Info:

  System:
    OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa)
    CPU: (14) x64 12th Gen Intel(R) Core(TM) i7-12700H
    Shell: 3.1.0 - /usr/bin/fish
  Binaries:
    Node: 22.5.1 - /usr/local/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm <----- active
    pnpm: 9.9.0 - ~/.local/share/pnpm/pnpm
  npmPackages:
    @storybook/addon-a11y: ^8.4.4 => 8.4.4 
    @storybook/addon-designs: ^8.0.4 => 8.0.4 
    @storybook/addon-docs: ^8.4.4 => 8.4.4 
    @storybook/addon-essentials: ^8.4.4 => 8.4.4 
    @storybook/addon-interactions: ^8.4.4 => 8.4.4 
    @storybook/angular: ^8.4.4 => 8.4.4 
    @storybook/channels: ^8.4.4 => 8.4.4 
    @storybook/core-events: ^8.4.4 => 8.4.4 
    @storybook/test: ^8.4.4 => 8.4.4 
    @storybook/test-runner: ^0.19.1 => 0.19.1 
    eslint-plugin-storybook: ^0.11.1 => 0.11.1 
    storybook: ^8.4.4 => 8.4.4

Additional context

A dirty fix to get it working is to not provide the component via the "component" option, but rather via the decorators property like this:

  decorators: [
    moduleMetadata({
      imports: [MyComponent],
    }),
  ],

We would not like to do it this way because it loses the ability to infer the argTypes

@json-derulo
Copy link

json-derulo commented Nov 20, 2024

Still happening in v8.5.0-alpha.9 which claims to support Angular 19.

@kurti-vdb
Copy link

kurti-vdb commented Nov 20, 2024

This is because the standalone: true option is missing in the component decorator. Although a workaround, if you add it by hand to the component, your stories will work. I guess it will also be the case for directives and pipes and that there won’t be a fast fix for this.

Created a stackoverflow issue for this too:
https://stackoverflow.com/q/79208200/4746087

@ingowagner
Copy link
Contributor

ingowagner commented Nov 20, 2024

I opened a PR that fixes this issue:
https://github.com/storybookjs/storybook/pull/29677/files

@droid-w
Copy link

droid-w commented Nov 21, 2024

This is because the standalone: true option is missing in the component decorator. Although a workaround, if you add it by hand to the component, your stories will work. I guess it will also be the case for services, directives, pipes… and that there won’t be a fast fix for this.

Created a stackoverflow issue for this too: https://stackoverflow.com/q/79208200/4746087

Hi man thanks, it work for me 👌👌👌👌

@kurti-vdb
Copy link

Still not fixed

@ingowagner
Copy link
Contributor

Still not fixed

Are you using version 8.5.0-alpha.10?

@json-derulo
Copy link

For me the issue fixed with version 8.5.0-alpha.10 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants