-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
[Angular] [bug] Automatic component declaration for Angular not working with forRoot
#7106
Comments
forRoot
forRoot
Maybe my issue (#7157) is related to this. Any work-a-rounds? |
@methodus Yes, your issue describes the same bug. I have a workaround (provided inside the collapsed diff above) which requires to edit the storybook source code inside node_modules but im willing to extract a PR from this issue changing the storybook code for a future release. Until the issue is fixed I would suggest to create a little script that applies the above diff and put that script in your npm / yarn |
Do you mean this commit? pascaliske/form-elements@3f00b3c |
@methodus yes but inside the
|
@pascaliske I ran your script and I can see that this line...
...was added in but I'm still seeing the same error in storybook. The
Any thoughts? |
forRoot
forRoot
EDIT: @cormickjbrowne I actually figured out why it does not work for you:
|
For my own Angular library I can confirm that the automatic component declaration works together with compiled files (built with |
Besides the problem with AOT-compiled code I would suggest to implement the following change which fixes the actual error from #7157 and my error with the Click to expand diff const extractNgModuleMetadata = (importItem: any): NgModule => {
+ const target = importItem && importItem.ngModule ? importItem.ngModule : importItem;
const decoratorKey = '__annotations__';
const decorators: any[] =
- Reflect && Reflect.getOwnPropertyDescriptor
- ? Reflect.getOwnPropertyDescriptor(importItem, decoratorKey).value
- : importItem[decoratorKey];
+ Reflect && Reflect.getOwnPropertyDescriptor && Reflect.getOwnPropertyDescriptor(target, decoratorKey)
+ ? Reflect.getOwnPropertyDescriptor(target, decoratorKey).value
+ : target[decoratorKey];
if (!decorators || decorators.length === 0) {
return null;
}
const ngModuleDecorator: NgModule | undefined = decorators.find(
decorator => decorator instanceof NgModule
);
if (!ngModuleDecorator) {
return null;
}
return ngModuleDecorator;
}; |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
It would be awesome if we can keep this open. I just provided a PR (#7224) to fix this error hopefully we can merge it. 😊 |
Ooh-la-la!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.2.0-beta.9 containing PR #7224 that references this issue. Upgrade today to try it out! You can find this prerelease on the Closing this issue. Please re-open if you think there's still more to do. |
The bugfix from the PR works as expected. Thanks! 🙂 |
Describe the bug
One of the last Storybook releases introduced a new behavior for NgModules where Storybook only declares components dynamically if they were not declared already inside of an imported NgModule (see #6666 - Thanks to @MaximSagan for his awesome work!).
This new behavior also introduces an error with NgModules imported by a static
forRoot
method which is a really common pattern for Angular apps:TypeError: Cannot read property 'value' of undefined
I already traced the error down to the line 60 in angular helpers. I would suggest to check the importItem for an existing key
ngModule
to identifyforRoot
-imports.Click to expand diff
I can provide a PR with this fix if you're fine with this change.
To Reproduce
Repo: https://github.com/pascaliske/form-elements
Branch:
feature/v8
Problematic line: https://github.com/pascaliske/form-elements/blob/feature/v8/.storybook/config.ts#L24
Steps to reproduce the behavior:
feature/v8
yarn run build && yarn run storybook
Expected behavior
Storybook can extract Metadata from imported NgModules both with or without
forRoot
.Screenshots
n/a
Code snippets
n/a
System:
Additional context
n/a
The text was updated successfully, but these errors were encountered: