-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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]: Storybook 7.5.3 -> Type [component] is part of the declarations of 2 modules: [module] and StorybookComponentModule! #24636
Comments
Update repo to storybook v7.5.3 version -> same issue. |
hi @meriturva, in two of the issues you link, each has a similar discovery (#22282 (comment), #23669 (comment)) -- it looks like, for some reasons unknown to us, the error |
I think I see the problem, but I would need to debug further to know if this can be fixed, without affecting the more common use case. You are creating a story for a dependency's component, which is not what Storybook expects. Storybook expects you to be adding stories for your project's components. Storybook iterates the NgModules, to see if you imported a module that already declared the component, when creating the Story's NgModule, so the Story's NgModule doesn't declare it a second time. Without looking into it more, I don't know why, but the reflection utility that is parsing the metadata is returning the declarations as This is typically is solved by using the dependency component in a component from your project, like dependencies should be used. Workaround if you still want to do it directly, even though I don't recommend it: The following is how I made your code work: // NOTE: I also added `import '@angular/localize/init';` to the top of `preview.ts`, but I am not using localize in my projects, so I don't know if that is how that should be done.
const meta: Meta<DropDownListComponent> = {
title: 'Kendo/DropDownList',
// NOTE: The component property is expecting a component from your project.
// component: DropDownListComponent,
decorators: [
// NOTE: The component was expecting animations module to be added so I also added this, also.
applicationConfig({
providers: [
provideAnimations(),
],
}),
moduleMetadata({
imports: [DropDownListModule]
}),
// You could pass a template string to this function or set the `template` property
// in the render function's return, also, if you need more control.
componentWrapperDecorator(DropDownListComponent)
],
tags: ['autodocs'],
render: (args: DropDownListComponent) => ({
props: {
...args,
},
})
}; |
I have tried import { type Meta, type StoryObj, moduleMetadata, applicationConfig, componentWrapperDecorator } from '@storybook/angular';
import { provideAnimations } from '@angular/platform-browser/animations';
import { DropDownListComponent, DropDownListModule } from '@progress/kendo-angular-dropdowns';
const meta: Meta<DropDownListComponent> = {
title: 'Kendo/DropDownList',
decorators: [
applicationConfig({
providers: [
provideAnimations(),
],
}),
moduleMetadata({
imports: [DropDownListModule]
}),
componentWrapperDecorator(DropDownListComponent, ({ args }) => ({
...args
}))
]
};
export default meta;
type Story = StoryObj<DropDownListComponent & { class : string }>;
export const Small: Story = {
args: {
data: ['X-Small', 'Small', 'Medium', 'Large', 'X-Large', '2X-Large'],
class: 'k-dropdownlist-sm'
},
}; bind correctly So my approach still: import { type Meta, type StoryObj, moduleMetadata, applicationConfig, componentWrapperDecorator } from '@storybook/angular';
import { provideAnimations } from '@angular/platform-browser/animations';
import { DropDownListComponent, DropDownListModule } from '@progress/kendo-angular-dropdowns';
const meta: Meta<DropDownListComponent> = {
title: 'Kendo/DropDownList',
decorators: [
applicationConfig({
providers: [
provideAnimations(),
],
}),
moduleMetadata({
imports: [DropDownListModule]
}),
render: (args: DropDownListComponent) => ({
template: `<kendo-dropdownlist ${argsToTemplate(args)}></kendo-dropdownlist>`,
props: {
...args
},
})
]
};
export default meta;
type Story = StoryObj<DropDownListComponent & { class : string }>;
export const Small: Story = {
args: {
data: ['X-Small', 'Small', 'Medium', 'Large', 'X-Large', '2X-Large'],
class: 'k-dropdownlist-sm'
},
};
|
@meriturva I am not sure what you mean by avoiding render. @valentinpalkovic I think this just pointed out a possible problem that, maybe is known and I just hadn't thought about it, yet. I don't know if there is a good way to catch and warn about it, though. If |
@Marklb, Good point! We should add an appropriate warning. Feel free to open an issue and label it with |
@meriturva Can you install the following snapshot release for all your Storybook packages: And then please try out your original approach: import { type Meta, type StoryObj, moduleMetadata } from '@storybook/angular';
import { DropDownListComponent, DropDownListModule } from '@progress/kendo-angular-dropdowns';
// More on how to set up stories at: https://storybook.js.org/docs/angular/writing-stories/introduction
const meta: Meta<DropDownListComponent> = {
title: 'Kendo/DropDownList',
component: DropDownListComponent,
decorators: [
moduleMetadata({
imports: [DropDownListModule]})
],
tags: ['autodocs'],
render: (args: DropDownListComponent) => ({
props: {
...args,
},
})
};
export default meta;
type Story = StoryObj<DropDownListComponent>;
// More on writing stories with args: https://storybook.js.org/docs/angular/writing-stories/args
export const Normal: Story = {
args: {
data: ['X-Small', 'Small', 'Medium', 'Large', 'X-Large', '2X-Large']
},
}; I am curious, whether it works then! |
@meriturva I made it work with the proposed snapshot release and I tiny adjustments around polyfilling and BrowserAnimations: Please take a look: meriturva/Storybook2ModulesError#1 |
@valentinpalkovic error running version
@Marklb I mean Thanks. |
@meriturva Can you start Storybook lets say 5 times? Does the error always occur? I know the issue but I have troubles to reproduce it. |
@valentinpalkovic 5 times out of 5 ... same error. |
The error is resolved together with the initial Angular problem. Storybook 7.6.0-alpha.5 will incorporate the changes as soon as it is released |
@valentinpalkovic thanks! now it works as expected! @Marklb @valentinpalkovic I have updated the repo adding a new story. and the new one using The main difference is that the Thanks. |
Unfortunately, I have no clue :/ Needs some further debugging and investigation. |
@meriturva The
That sort of limitation is why I haven't actually switched to |
Describe the bug
I'm migrating our solution from mdx (1.x) stories to a new modern way (using stories.ts files).
My first attempt is to migrate a few stories about external customized components (es Kendo Components) to straightforward stories.
So basically I have a story like:
Unfortunately, I got the error:
Error: Type DropDownListComponent is part of the declarations of 2 modules: DropDownListModule and StorybookComponentModule! Please consider moving DropDownListComponent to a higher module that imports DropDownListModule and StorybookComponentModule. You can also create a new NgModule that exports and includes DropDownListComponent then import that NgModule in DropDownListModule and StorybookComponentModule.
To Reproduce
Please clone repo:
https://github.com/meriturva/Storybook2ModulesError
just run:
npm run storybook
and go to page: http://localhost:6006/?path=/docs/kendo-dropdownlist--docsSystem
No response
Additional context
The same issue is already described:
#23669
#22282
#19289
but no one in version 7.5x
The text was updated successfully, but these errors were encountered: