-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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]: NgModule is imported twice #21284
Comments
@sheriffMoose @valentinpalkovic is this something either of you know about? |
Yes, working on it already. |
It doesn't happen only for a Module.forRoot(), it also happens for modules that are needed to be imported only once in the application like BrowserModule and BrowserAnimationsModule. Once you create a story that imports these modules (especially since BrowserAnimationsModule is needed) you get a runtime error: Hey @valentinpalkovic, I would be happy to know of a timeline for a fix. Thanks! |
@rezoled the error should not occur for BrowserAnimationModule, because we handle this separately. Please provide a reproduction in a separate issue, because this is unrelated to this one. |
The timeline is to work on this bug this or next week. |
What about this error, is it the same bug? |
That's related to the same error mentioned in this issue |
I think I understand the issue with BrowserAnimationsModule, when I import it like this:
It throws |
Another error I get is:
It seems that Angular tries to generate the same module twice for the same context. |
You can fix the browser animation error by applying the following code: {
...
imports:[isDev ? NoopAnimationsModule : BrowserAnimationsModule]
} |
@rezoled This is another error and does not relate to this Github Issue. Please open a new issue with a reproduction. |
Great Caesar's ghost!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.0-rc.11 containing PR #21770 that references this issue. Upgrade today to the
|
@shilman we have upgraded to RC11 and we still see this error:
This is migrating an existing moduleMetadata that used to work in version 6. |
@jinder Please follow the migration guide: https://github.com/storybookjs/storybook/blob/v7.0.0-rc.11/MIGRATION.md#angular-application-providers-and-modulewithproviders |
@valentinpalkovic thanks - this now works! We were getting some strange errors because a child module was importing BrowserAnimationsModule directly. |
@jinder i think BrowserAnimationsModule should always be imported on the root level and should never be imported by a child module if I am not wrong. Please open a new issue, if you still have problems |
@valentinpalkovic I think you're right, however Angular doesn't error or warn you. It's only apparent when using Storybook and the errors were a bit confusing. It all works now though, thank you! |
I'm still getting duplicate module error:
The test:
avatar.module:
I tried running ``npx sb@next upgrade --prerelease``` but I got error while running migrations.
Is it something I'm doing wrong? Could it be because of the migration error? |
@rezoled please open a new issue and mention me, because this issue was about the forRoot pattern (and if possible, please provide a reproduction). I have already a solution in mind for your problem. I will take a look on Monday. |
No problem, opening a new issue. Meanwhile I checked and the problem was not from the broken migration |
Describe the bug
When an
NgModule
follows theforRoot
pattern (https://angular.io/guide/singleton-services#prevent-reimport-of-the-greetingmodule), the module appears to be loaded twice and produces a runtime error indicating that the module was already loaded.Note this pattern works fine in Angular 15 environment.
To Reproduce
System
Additional context
Is it possible that the
@SkipSelf
is not being respected on the Module constructor parameter? Possibly related to this? #21243Is it appropriate to import
forRoot
modules in the Story metadata? Do we need a "special" property for root imports perhaps?The text was updated successfully, but these errors were encountered: