storybook: @storybook/angular does not work with Angular Ivy
Describe the bug The problem is that I get runtime exception, when I open some story of some Angular Component. The component is not starting.
To Reproduce
Steps to reproduce the behavior (ready repro):
1 Clone the repro: git clone git@github.com:sharikovvladislav/angular-ivy-storybook-repro.git (or use HTTPS link: https://github.com/sharikovvladislav/angular-ivy-storybook-repro.git)
2 Go to the created directory: cd angular-ivy-storybook-repro
3 Install the dependencies: yarn
4 Start the storybook: yarn run storybook
5 Open the browser console
Steps to reproduce on the clear example:
Preconditions: stable @angular/cli is installed (8.3.8 at the moment, npm i -g @angular/storybook) globally and you have also @storybook/angular installed (npm i -g @storybook/cli).
1 Execute ng new <your-name> --defaults --enable-ivy (or without defaults, just put default values, when ng will ask you to interact)
2 Execute cd <your-name> command
3 Execute sb init
4 Execute ./node_modules/.bin/ivy-ngcc command (this is required by Angular to get Ivy working and probably this step can produce the problem)
5 Go to the src/stories/1-Button.stories.ts and put the following code:
import { storiesOf } from '@storybook/angular';
import { AppComponent } from '../app/app.component';
storiesOf('App Component', module).add('Component with separate template', () => ({
component: AppComponent,
props: {},
}));
6 Run the npm run task yarn run storybook or npm run storybook
7 Open the browser console
Expected behavior
I expect simple story with woot text in it and no exceptions in the console.
Actual result
I am getting this error in the console:
ERROR TypeError: Cannot read property 'clear' of undefined
at SafeSubscriber._next (vendors~main.54eb421…3c3.bundle.js:81321)
at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (vendors~main.54eb421…c3.bundle.js:155128)
at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (vendors~main.54eb421…c3.bundle.js:155066)
at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next (vendors~main.54eb421…c3.bundle.js:155010)
at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (vendors~main.54eb421…c3.bundle.js:154987)
at TapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/tap.js.TapSubscriber._next (vendors~main.54eb421…c3.bundle.js:163002)
at TapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (vendors~main.54eb421…c3.bundle.js:154987)
at TakeSubscriber.push../node_modules/rxjs/_esm5/internal/operators/take.js.TakeSubscriber._next (vendors~main.54eb421…c3.bundle.js:162714)
at TakeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (vendors~main.54eb421…c3.bundle.js:154987)
at ReplaySubject.push../node_modules/rxjs/_esm5/internal/ReplaySubject.js.ReplaySubject._subscribe (vendors~main.54eb421…c3.bundle.js:1
And I don’t see the rendered text wooot.
Screenshots

Code snippets
The story code is above (in one of the repros).
The component code:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: `
<span>woot</span>
`
})
export class AppComponent {
title = 'with-ivy';
}
It references this.target.clear line in your AppComponent in the storybook source code. Here is this line
System:
Environment Info:
System:
OS: macOS Mojave 10.14.6
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Binaries:
Node: 10.16.0 - /usr/local/bin/node
Yarn: 1.17.3 - /usr/local/bin/yarn
npm: 6.9.0 - /usr/local/bin/npm
Browsers:
Chrome: 77.0.3865.90
Safari: 13.0.2
npmPackages:
@storybook/addon-actions: ^5.2.3 => 5.2.3
@storybook/addon-links: ^5.2.3 => 5.2.3
@storybook/addon-notes: ^5.2.3 => 5.2.3
@storybook/addons: ^5.2.3 => 5.2.3
@storybook/angular: ^5.2.3 => 5.2.3
npmGlobalPackages:
@storybook/cli: 5.2.3
Additional context
- I am using
@angular/core@8.2.9with Ivy enabled. ivy-ngccis a tool to makenode_modulesIvy compatible.- with Ivy disabled everything works correctly
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 7
- Comments: 31 (8 by maintainers)
I had the same error as stated in the issue description and it disappeared after upgrading to
"@storybook/angular": "5.3.0-rc.7"same question here, is there any workaround available?
Looks like it is same using latest
angularversion (in my project, not in storybook).Here is the list of known issues: https://docs.google.com/document/d/1Dije0AsJ0PxL3NaeNPxpYDeapj30b_QC0xfeIvIIzgg/preview I found it there: https://blog.angular.io/its-time-for-the-compatibility-opt-in-preview-of-ivy-38f3542a282f
Probably, this can cause error:
Let me fully reinstall
node_modulesand check it again. UPD: absolutely same.If I understand correctly, I don’t need compile
node_moduleswithivy-ngcccommand inangular@9.0.0-next.10. Probably , this happens on the fly now. Looks like@storybook/angularpackage innode_modulesfolders is not processed at all. OnAngular@8version when I calledivy-ngcctool manually,storybook/angulardidn’t appear in list of processed libraries.There are some news about this issue?
Wait :DDD
It is just an error in console. Storybook started, whil I was typing the previous message.
I have this exception while storybook is starting:
But in general, storybook started and works fine. In Ivy. In our huge project 😃
Arrrgh… In our project we don’t
@angular/cliat the moment. My mate @nickbullock has this task at the moment 😄I can’t start storybook in our project, since it does not have
angular-devkitdependency at the moment. Looks like you need it to get webpack-configs. We have webpack configs extracted (well, actually Angular and Angular CLI did not exist at that moment in the past 😄).Oh really? That’s what I have fixed 😄 Haven’t expected that it fixes the usage of Ivy as well Let me confirm this and we might be able to close this. Thanks for all your efforts! It helped a lot.
Looks like it is fixed in alpha.18 according to the CHANGELOG.md file. It works on
alpha.19.Interesting. I somehow managed to run Ivy instead of the view engine in my project.
Reproduction
Result
ivy-ngccI had no problems. Everything looked as expected (using AppComponent as a story component)ivy-ngccI got 0 errors (the one in the screenshot is something different) but somehow not the entire template / styles are rendered/appliedRegarding the missing entry for @storybook/angular in ivy-ngcc
Currently,
@storybook/angularis compiled bytscbecause we can’t run the angular compiler so far. Maybe it is now possible using ivy-ngcc but it wasn’t possible (or at least I haven’t figured out how) withngcbecause we have no real angular projectThis is how we create the module that is used to display a story in Angular
https://github.com/storybookjs/storybook/blob/next/app/angular/src/client/preview/angular/helpers.ts#L29
Also worth mentioning
I set
aotto true in myangular.jsonbut the generated code usesjit_Somehow@storybook/angularuses jit and ignores theaot: true- I’m not even sure how activateaotprogrammatically 🤔Thank you very much for helping out here!
Now lets compile node_modules using
ivy-ngcctool:And lets execute
npm run storybookcommand again.Now we don’t have ngfactories (so Ivy is enabled now):
This is how compiled code of the AppComponent looks like:
This is
this.targetvalue now:This refers to AppComponent (its correct):
ngContextinthis, that also means that Ivy is working.@kroeder I think the problem is not about
rxjs. It is just a call stack. Your code usesrxjs. Here is it:https://github.com/storybookjs/storybook/blob/next/app/angular/src/client/preview/angular/components/app.component.ts:
The problem appears in this line: https://github.com/storybookjs/storybook/blob/next/app/angular/src/client/preview/angular/components/app.component.ts#L44
this.targetis a result of ViewChild query: https://github.com/storybookjs/storybook/blob/next/app/angular/src/client/preview/angular/components/app.component.ts#L30Thanks for reporting this! I wanted to test Ivy as well and had hoped it just works 😬 This is really something we have to fix before Angular 9 is released @shilman - I will start working on this soon
Clarification for non-angular users Ivy is the new rendering engine of Angular and is currently “opt-in” in Angular 8. It’s becoming “opt-out” in Angular 9 so basically every new project starting with Angular 9 will run with Ivy
They are still having
nextreleases and noalpha,betaorrcbut it will be released around november I think https://angular.io/guide/releases#release-schedule@sharikovvladislav I would appreciate any kind of help - I’m not yet familiar with Ivy and the problems it may cause