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.

[Angular] TypeError: Cannot read property 'value' of undefined

See original GitHub issue

Describe the bug When using a decorator to provide required modules to an angular component, storybook throws the error below:

TypeError: Cannot read property 'value' of undefined
    at extractNgModuleMetadata (VM82 vendors~main.a7bca498af84c7b1b5b6.bundle.js:89276)
    at VM82 vendors~main.a7bca498af84c7b1b5b6.bundle.js:89296
    at Array.some (<anonymous>)
    at getExistenceOfComponentInModules (VM82 vendors~main.a7bca498af84c7b1b5b6.bundle.js:89295)
    at initModule (VM82 vendors~main.a7bca498af84c7b1b5b6.bundle.js:89312)
    at push../node_modules/@storybook/angular/dist/client/preview/angular/helpers.js.exports.renderNgApp (VM82 vendors~main.a7bca498af84c7b1b5b6.bundle.js:89346)
    at render (VM82 vendors~main.a7bca498af84c7b1b5b6.bundle.js:89468)
    at renderMain (VM82 vendors~main.a7bca498af84c7b1b5b6.bundle.js:91789)
    at StoryStore.renderUI (VM82 vendors~main.a7bca498af84c7b1b5b6.bundle.js:91813)
    at StoryStore.emit (VM82 vendors~main.a7bca498af84c7b1b5b6.bundle.js:116462)

To Reproduce Steps to reproduce the behavior:

  1. Create an Angular component
  2. Create an Angular module which declares and exports the component and additionally imports other required modules from Angular
  3. Create a story with a decorator to provide the module
  4. Start storybook and select the story, error is shown on screen and in the console.

Expected behavior The component is shown as expected

Screenshots https://ibb.co/zmBBPgv

Code snippets

Module

@NgModule({
  declarations: [
    MapComponent
  ],
  imports: [
    CommonModule,
    NgxMapboxGLModule
  ],
  exports: [
    MapComponent,
    NgxMapboxGLModule
  ]
})
export class MapModule { }

Story

storiesOf('Map|Map', module)
  .addDecorator(
    moduleMetadata({
      imports: [
        MapModule,
      ]
    })
  )
  .add('Simple map without parameters', () => ({
    component: MapComponent
  }))

System:

  • OS: Windows10
  • Browser: chrome
  • Framework: angular 7.2.0
  • Version: 5.2.0-alpha.23

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:13
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

12reactions
ManuelRaubercommented, Jun 28, 2019

A current workaround for me seems to be to do:

storiesOf('core | core/MyComponent', module)
  .add('default', () => ({
    component: MyComponent,
    moduleMetadata: {
      declarations: [MyComponent], // Adding this brings it back to live
      imports: [
        TranslateModule.forRoot(),
      ],
    },
  }));
9reactions
pascaliskecommented, Jul 25, 2019

FYI: My PR (#7224) for this bug was recently merged into next! 🎉😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 6 - ERROR TypeError: Cannot read property 'value' of ...
Angular 7 - ERROR TypeError: Cannot read property 'value' of undefined. You can check for the object value by using the ? operator....
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError: Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
How to Avoid the Infamous "Cannot read properties of ... - Bitovi
That error message is telling you the function is returning undefined implicitly, but its return type does not include undefined in it. Awesome!...
Read more >
cannot read properties of undefined (reading 'value') in angular
If the element at index 0 contains the innerHTML property, our if block will run, otherwise the else block is run. To solve...
Read more >
ANGULAR 13 TypeError Cannot read property of undefined
In this tutorial, we will see a most common error faced by the Angular developers named as " TypeError Cannot read property of...
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