-
-
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
[6.2.0-beta.1] Angular example stories throw "Unhandled Promise rejection: Type ButtonComponent is part of the declarations of 2 modules: StorybookModule and StorybookModule!" #14026
Comments
hi ✌️ , I tried on a fresh install
The problem also occurs on version
|
I have the same issue. Any ideas or suggestions?
|
I just tested with |
Seems my message was premature. :) It's still occurring but I need to figure out exactly what triggers it because for a few minutes it was working well, |
I am also having this issue, trying to investigate it... |
let me know if you figure something out. I am desperately looking for a workaround |
I just had the problem again, on
Its works. |
@snutij Can confirm the sorcery. |
@snutij running I was only receiving this message when I saved modules/components/directives/etc. I found |
this is still a blocking issue for me with the latest version (6.2.8 and also 6.3.0-alpha.10). I tried the approach/workaround from @snutij, but with no effect. |
I have one project where this happens when I don't use @NgModule for the component. To get around it I just added an NgModule with the component declaration and then added the module to the default story export in moduleMetadata. In a standard storybook install this doesn't happen so I'm trying to find out how to recreate it properly so we can hopefully get this fixed |
I spent a good part of 2 days on this. I don't know why, but the problem seems to be when a story has a module metadata decorator that has declarations:
The solution I found to this was to create a module that declares and exports this component.
|
@snutij Solution worked. But what I'm even more stoked about is |
I could now reproduce the bug. It is because of ngcc.
Navigating to a story once works... if you go again to the same story, it breaks. Repo to check: https://github.com/mangei/storybook-ngcc-bug I did not find a solution yet, how to fix that... |
Getting this as well (6.2.9), in an addon-docs setup with MDX, e.g. <Meta
title="Detail Cards/Vessel Card"
decorators={[withKnobs, moduleMetadata({ imports: [DecanterUiModule, DetailsCardsModule, CommonModule], declarations: [] })]}
/>
<Canvas>
<Story name="Empty Vessels">
{{
template: `<some-component></some-component>`
}}
</Story>
</Canvas> When changing SomeComponent the error will appear with a whole lot of duplicates. Might be an issue with HMR in this scenario, however this worked in previous angular/storybook versions. |
Just did a clean install and this is still happening with the example stories. I didn't even have to write a single line of code myself for the error to throw. I did, however have to click on the Example button story twice. I first viewed the Primary example and then when I clicked on the Secondary example the error occurred. This is happening on the official release version 6.2.9 for me, not BETA. Still using node 12.10.0 and npm 6.10.3 |
Happend to me once I updated to @storybook/angular from 6.2.8 to 6.2.9, but because I use nx.dev and I ran its migration tool, it also updated @angular/core from 11.0.0 to 11.2.0 (among other things). Downgrading @storybook/angular to 6.2.8 didn't work, so I thought, it's gotta be @angular, so: I stepped back with nx migration and used @angular/core 11.0.0 + updated to @storybook/angular 6.2.9, guess what? worked! (did it twice, removing node_modules folder) _I didn't try the @NgModule export thing just yet, I'm gonna _ |
My guess it has something to do with angular decorating things in node_modules to be Ivy compatible, essentially rewriting some stuff in node_modules. By reinstalling node_modules you essentially remove what angular has done and storybook works as expected - for a while at least. I think that this works until you build with angular tools again, at witch point it redecorates and you get the same error. |
I'm wondering if the way we create our stories is right:
Problem when No problem when No problem when |
The issue was inside ngcc for me, not running that resolves the issue. Possibly also why Seems to be added in 6.3.0-alpha.11.. 6.3.0-alpha.19 is working fine to me. |
Face this issue too. It was solved using |
use |
edit: I included the whole code block, as the 3 lines didn't provide any context |
I confirm what @davicoradini said, the problem is in ngcc. Eliminating postinstall ngcc fixes the issue. |
I implemented what @tuuling mentioned using a specific module for the component I wanted to use 2+ times. Fwiw, this was using the latest nx storybook projects setup. Here's what worked for me: // Created module ButtonModule
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { ButtonComponent } from './button.component';
@NgModule({
imports: [CommonModule],
declarations:[ButtonComponent],
exports:[ButtonComponent]
})
export class ButtonModule {} And then was able to reuse this across various buttons like: // Default button
import { text } from '@storybook/addon-knobs';
import { ButtonModule } from './button.module';
import { ButtonComponent } from './button.component';
export default {
title: 'Default Button',
};
export const DefaultButton = () => ({
moduleMetadata: {
imports: [ButtonModule]
},
component: ButtonComponent,
props: {
label: text('label', 'Default Button'),
css: text('css', 'btn')
}
});
// Primary button
import { text } from '@storybook/addon-knobs';
import { ButtonModule } from './button.module';
import { ButtonComponent } from './button.component';
export default {
title: 'Primary Button',
};
export const PrimaryButton = () => ({
moduleMetadata: {
imports: [ButtonModule]
},
component: ButtonComponent,
props: {
label: text('label', 'Primary Button'),
css: text('css', 'btn btn-primary')
}
}); ...and so on. I'm an angular noob, but I wanted to figure out how to get it working this way as I suspect the error is legitimate in how Angular wants you to do things using ngmodules. So maybe this isn't really a bug ¯_(ツ)_/¯? UPDATE: I hit this again recently and it was due to forgetting to export the component from a shared module fwiw — also a usage error I think. |
You need to add the If you're using Nx just modify postinstall in your package.json to this below then delete your node_modules dir and do an
|
@dexster for me it's vice versa. In my NX environment I've removed postinstall ngcc call and Storybook started to work properly. But with ngcc as part of postinstall it doesn't work. |
@KirillMetrik We're saying the same thing. ngcc does not work by default in NX. Instead of removing the postinstall you can just add |
Thank you @dexster for the tip. Storybook works well with |
I have found the issue: @NgModule({
declarations: [ButtonComponent],
imports: [CommonModule],
exports: [ButtonComponent],
})
export class ButtonModule {} export default {
title: 'Components/Core/Button',
component: ButtonComponent,
decorators: [
moduleMetadata({
declarations: [],
imports: [ButtonModule],
}),
],
} as Meta;
const Overview: Story<ButtonComponent> = (args) => ({
props: args,
template: `
<button loButton [variant]="variant" [size]="size" type="button" >
Button
</button>
</div>
`,
}); the problems lies here:
when we have import that exports and component and we want to use So In short, storybook should not declare components passed to //checked at storybook 6.3.4 |
I hit this among a bunch of other issues while trying to upgrade dependencies on a monorepo of UI components. A separate, apparently distinct, issue was related to i18n, and after adding import of @angular/localize/init in preview.js, this 'declaration of 2 modules' issue went away as well 🤷 All I did was add @angular/localize as a dev dependency, then add the following to preview.js: import '@angular/localize/init'; If I simply comment out the import, the issue comes back. This angular storybook previously worked fine without this (angular 11.2.6, storybook 6.1.21), but requires it post upgrade (angular 12.2.13, storybook 6.3.12). Note even the original version was already after angular introduced this i18n stuff. |
removing the following from
|
So in our case this was "fixed" by using a consolidating module that gets imported over the component import in |
@activenode no. I get the error either way. I think it has to do with the stories also being rendered in MDX. |
As soon as I go and comment out all the stories being referenced in the MDX docs, there error goes away. |
I'm still facing the same error here. (Storybook at version 6.5.9). When I write the stories using MDX, there is this error of the declaration of 2 modules. When I write the "same" stories using CSF, the error does not happen. :( I tried all the previous possible solutions, and none worked. |
I'm getting roughly the same error. To be honest, I can't even figure out where all of these Components in the "stories" directory are even being put in a Module at all. |
What worked for me was setting the |
. |
I just upgraded Storybook from 6.3.12 to 6.5.10 and I got the error. Thank you @ArturQuirino! Your workaround work for me as well. |
It works for me. But maybe you know how to Remove scrollbar from iFrame without story height changes? |
I tried iFrame solution with docs: { inlineStories: false } storybook v6.5.12. But it has performance issues that make this solution unusable :( |
@michelepatrassi does this issue still exist in 7.0 beta? @andykono in 7.0 beta inline rendering has been overhauled, and iframe-rendering discouraged. |
This PR fixes the issue: #20559 |
Boo-yah!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.0-beta.30 containing PR #20559 that references this issue. Upgrade today to the
Closing this issue. Please re-open if you think there's still more to do. |
Describe the bug
Switching the examples stories (like the ButtonComponent) throws an error in the console and the component is not rendered at all. Works the first time, but as soon as you go to the same component stories is gonna throw this
To Reproduce
Steps to reproduce the behavior:
npx sb upgrade --prerelease
)Expected behavior
No errors are thrown and component can render in every story
Screenshots
If applicable, add screenshots to help explain your problem.
System
Additional context
My main goal was to get this change in #10272 (comment) so I could manage the component ng-content. Also tried to install 6.2.0-alpha.13 directly but can see this issue there as well (plus the UI is flickering, but that seems fixed in later versions)
The text was updated successfully, but these errors were encountered: