question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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!"

See original GitHub issue

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

Unhandled Promise rejection: Type ButtonComponent is part of the declarations of 2 modules: StorybookModule and StorybookModule! Please consider moving ButtonComponent to a higher module that imports StorybookModule and StorybookModule. You can also create a new NgModule that exports and includes ButtonComponent then import that NgModule in StorybookModule and StorybookModule. ; Zone: <root> ; Task: Promise.then ; Value: Error: Type ButtonComponent is part of the declarations of 2 modules: StorybookModule and StorybookModule! Please consider moving ButtonComponent to a higher module that imports StorybookModule and StorybookModule. You can also create a new NgModule that exports and includes ButtonComponent then import that NgModule in StorybookModule and StorybookModule.
    at verifySemanticsOfNgModuleDef (core.umd.js:27446)
    at Function.get (core.umd.js:27384)
    at getInjectorDef (core.umd.js:365)
    at R3Injector.push../node_modules/@angular/core/bundles/core.umd.js.R3Injector.processInjectorType (core.umd.js:11537)
    at core.umd.js:11401
    at core.umd.js:4380
    at Array.forEach (<anonymous>)
    at deepForEach (core.umd.js:4380)
    at new R3Injector (core.umd.js:11401)
    at createInjectorWithoutInjectorInstances (core.umd.js:11373) 

To Reproduce Steps to reproduce the behavior:

  1. install 6.2.0-beta.1 (currently just npx sb upgrade --prerelease)
  2. Open the console
  3. Click on the button primary story
  4. Click on the button secondary story
  5. See error in console and component does not show

Expected behavior No errors are thrown and component can render in every story

Screenshots If applicable, add screenshots to help explain your problem. image

System

Environment Info:

  System:
    OS: macOS 11.3
    CPU: (4) x64 Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
  Binaries:
    Node: 12.11.1 - ~/.nvm/versions/node/v12.11.1/bin/node
    Yarn: 1.3.2 - /usr/local/bin/yarn
    npm: 6.11.3 - ~/.nvm/versions/node/v12.11.1/bin/npm
  Browsers:
    Chrome: 88.0.4324.192
    Firefox: 81.0.2
    Safari: 14.1
  npmPackages:
    @storybook/addon-actions: ^6.2.0-beta.1 => 6.2.0-beta.1 
    @storybook/addon-essentials: ^6.2.0-beta.1 => 6.2.0-beta.1 
    @storybook/addon-links: ^6.2.0-beta.1 => 6.2.0-beta.1 
    @storybook/angular: ^6.2.0-beta.1 => 6.2.0-beta.1 

Additional context My main goal was to get this change in https://github.com/storybookjs/storybook/issues/10272#issuecomment-759355272 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)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:21
  • Comments:42 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
ghostcommented, Mar 22, 2021

@snutij Can confirm the sorcery.

5reactions
tuulingcommented, Apr 24, 2021

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:

decorators: [
    moduleMetadata({
       declarations: [MyComponent]
    })
  ]

The solution I found to this was to create a module that declares and exports this component.

@NgModule({
  declarations: [
    MyComponent
  ],
  exports: [
    MyComponent
  ]
})
export class MyModule
...
decorators: [
    moduleMetadata({
       declarations: [MyModule]
    })
  ]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Storybook Component is part of two modules error
I believe that's how it ends up in DynamicModule, and then moduleMetadata's import is getting it the second way. One solution is to...
Read more >
How to fix Error: Type is part of the declarations of 2 modules
A solution for Angular tests when they fail with "Type is part of the declarations of 2 modules"
Read more >
Component Is Part Of The Declarations Of 2 Modules - ADocLib
I have created a component called commonmod.component.ts that I am including in two other modules abc and def. abc.module.ts import { commonmod }...
Read more >
A complete guide to Angular libraries - Will Taylor Blog
One of the things that was introduced in Angular 6 was the ability to create and build libraries with the Angular CLI.
Read more >
'formsmodule' does not appear to be an ngmodule class.
import {NgModule} from '@angular/core'; import {CommonModule} from '@angular/common'; ... Type page is part of the declarations of 2 modules error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found