Angular 19 and Storybook 8.4.4: Storybook still requires the standalone option - Stack Overflow

I upgraded my angular UI library to Angular 19 and storybook 8.4.4. At the time being, these are both t

I upgraded my angular UI library to Angular 19 and storybook 8.4.4. At the time being, these are both the latest version. With Angular-cli 19, standalone components become the default choice, where the standalone: true option is not present anymore in the decorator, like:

Before Angular 19 (14, 15, 16, 17, 18)

@Component({
  standalone: true,
  imports: [CommonModule],
  selector: 'app-my-component',
  templateUrl: './my-component.html',
})
export class MyComponent { }

Angular 19

@Component({
  imports: [CommonModule],
  selector: 'app-my-component',
  templateUrl: './my-component.html',
})
export class MyComponent { }

This breaks however when trying to run Storybook. When the standalone option is not present in the decorator, this results in a declaration error:

Error: Unexpected "ButtonComponent" found in the "declarations" array of the "StorybookComponentModule" NgModule. ButtonComponent" is marked as standalone and can't be declared in any NgModule - did you intend to import it instead (by adding it to the "imports" array)?

Apparently, the declarations error in Storybook occurs because Storybook internally generates a temporary Angular module (StorybookComponentModule) to wrap components and their metadata. This module is not visible, but it is where Storybook attempts to add the component to the declarations array.

So for the moment, the only fix is to manually add the option to the component. I guess it will also be the case for pipes and directives.

I upgraded my angular UI library to Angular 19 and storybook 8.4.4. At the time being, these are both the latest version. With Angular-cli 19, standalone components become the default choice, where the standalone: true option is not present anymore in the decorator, like:

Before Angular 19 (14, 15, 16, 17, 18)

@Component({
  standalone: true,
  imports: [CommonModule],
  selector: 'app-my-component',
  templateUrl: './my-component.html',
})
export class MyComponent { }

Angular 19

@Component({
  imports: [CommonModule],
  selector: 'app-my-component',
  templateUrl: './my-component.html',
})
export class MyComponent { }

This breaks however when trying to run Storybook. When the standalone option is not present in the decorator, this results in a declaration error:

Error: Unexpected "ButtonComponent" found in the "declarations" array of the "StorybookComponentModule" NgModule. ButtonComponent" is marked as standalone and can't be declared in any NgModule - did you intend to import it instead (by adding it to the "imports" array)?

Apparently, the declarations error in Storybook occurs because Storybook internally generates a temporary Angular module (StorybookComponentModule) to wrap components and their metadata. This module is not visible, but it is where Storybook attempts to add the component to the declarations array.

So for the moment, the only fix is to manually add the option to the component. I guess it will also be the case for pipes and directives.

Share Improve this question edited Nov 21, 2024 at 9:00 Kurt Van den Branden asked Nov 20, 2024 at 16:42 Kurt Van den BrandenKurt Van den Branden 13k10 gold badges80 silver badges90 bronze badges 1
  • 1 A PR is pending to fix this : github/storybookjs/storybook/pull/… – Matthieu Riegler Commented Nov 20, 2024 at 19:55
Add a comment  | 

1 Answer 1

Reset to default 0

The storybook release 8.4.5 (released on November 20, 2024) fixes this:

  • Angular: Support v19 - #29659

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742343780a4426136.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信