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: CommonModule issue with 6.3 when using moduleMetadata

See original GitHub issue

Describe the bug

In 6.3.0-beta-4 with Angular v12, CommonModule is not loading correctly and causing errors like: NG0303: Can't bind to 'ngIf' since it isn't a known property of 'div'.

This works correctly on 6.2.9 with ng v11. I still need to check whether this works with 6.3 and ng v11.

To Reproduce

With Angular v12 installed.

ng new testsb cd into testsb npx sb@next init

In button.component.ts add a module

@NgModule({
  imports: [CommonModule],
  declarations: [ButtonComponent],
  exports: [ButtonComponent]
})
export class ButtonModule {
} 

Still in button.component.ts, add an *ngIf to the ButtonComponent template

@Component({
  selector: 'storybook-button',
  template: `<button *ngIf="true"
...

Add the module to the story - button.stories.ts

export default {
  title: 'Example/Button',
  component: Button,
  decorators: [
    moduleMetadata({
      imports: [ButtonModule]
    })
  ],
  argTypes: {
    backgroundColor: {control: 'color'},
  },
} as Meta;

npm run storybook and view console.log

Additional info The reason I am using moduleMetadata in my scenario is because of this issue, #14026, which requires the addition of a module declaration to work around it

System System: OS: macOS 11.4 CPU: (12) x64 Intel® Core™ i7-9750H CPU @ 2.60GHz Binaries: Node: 14.15.5 - ~/.nvm/versions/node/v14.15.5/bin/node Yarn: 1.22.10 - ~/.nvm/versions/node/v14.15.5/bin/yarn npm: 6.14.11 - ~/.nvm/versions/node/v14.15.5/bin/npm Browsers: Chrome: 91.0.4472.77 Edge: 90.0.818.66 Firefox: 88.0.1 Safari: 14.1.1 npmPackages: @storybook/addon-actions: ^6.3.0-beta.4 => 6.3.0-beta.4 @storybook/addon-essentials: ^6.3.0-beta.4 => 6.3.0-beta.4 @storybook/addon-links: ^6.3.0-beta.4 => 6.3.0-beta.4 @storybook/angular: ^6.3.0-beta.4 => 6.3.0-beta.4 @storybook/builder-webpack5: ^6.3.0-beta.4 => 6.3.0-beta.4 @storybook/manager-webpack5: ^6.3.0-beta.4 => 6.3.0-beta.4

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dexstercommented, May 31, 2021

@ThibaudAV I don’t have the problem anymore. Check my last comment. Adding the create-ivy-entry-points option and then reinstalling node modules fixes it.

1reaction
dexstercommented, May 29, 2021

@shilman @ThibaudAV I left out a vital piece of information. I had also manually run ngcc --properties es2015 browser module main after the npm install to simulate an nx project as my real project uses nx. This issue only occurs after running this command.

This is what nx does after install "postinstall": "node ./decorate-angular-cli.js && ngcc --properties es2015 browser module main",

If we add this option --create-ivy-entry-points then the issue disappears. It also fixes issue #14026

I would suggest we ask the nx team to change the postinstall to: "postinstall": "node ./decorate-angular-cli.js && ngcc --properties es2015 browser module main --create-ivy-entry-points",

Anyone currently experiencing the issue can simply add this option manually, delete their node_modules dir and npm install

Read more comments on GitHub >

github_iconTop Results From Across the Web

CommonModule - Angular
A structural directive that conditionally includes a template based on the value of an expression coerced to Boolean. When the expression evaluates to...
Read more >
core.mjs:7505 ng0303: can't bind to 'ngif' - You.com - You.com
storybookjs/storybookAngular: CommonModule issue with 6.3 when using ... info The reason I am using moduleMetadata in my scenario is because of this issue, ......
Read more >
Storybook for Angular not displaying elements created by ...
I am trying to use Storybook for an Angular project. ... The issue is any piece of a component template using a kendo...
Read more >
Does not have 'ɵmod' property for imported modules (Angular ...
I ran into this issue after migrating Angular to versions 10,11,12, ... decorators: [ moduleMetadata({ declarations: [LibComponent], imports: [CommonModule ...
Read more >
Angular Storybook Component is part of two modules error
The alternative is to use the template prop instead of the component prop: import {moduleMetadata, storiesOf} from '@storybook/angular'; ...
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