nx: Storybook not loading - Uncaught undefined
Current Behavior
- Nx 13.3.0
- Angular 13.0.3
- @storybook/angular 6.4.5
Running the nx run storybook:<project> command successfully builds and deploys Storybook, but when navigating to http://localhost:4400 it only displays a blank page and throws some errors in the console (see below).
Expected Behavior
Storybook should should start without errors.
Steps to Reproduce
I have created a reproduction here: https://github.com/klingebiel/nx-storybook-issue
You can run npm run storybook and navigate to http://localhost:4400 to reproduce the issue.
I set up the workspace with the following steps:
- Create empty workspace with
create-nx-workspace - Add Angular application
- Add Angular library
- Add Storybook configuration for library
Failure Logs
vendors-node_modules_storybook_addon-actions_dist_esm_register_js-node_modules_storybook_addo-f09f2b.manager.bundle.js
> Uncaught undefined
> The above error occurred in one of your React components:
in Unknown (created by Scroller)
in Suspense (created by Scroller)
in Scroller (created by Context.Consumer)
in Styled(Scroller)
in Unknown (created by Context.Consumer)
in Bar (created by FlexBar)
in FlexBar (created by Tabs)
in div (created by Context.Consumer)
in Styled(div) (created by Tabs)
in Tabs
in Tabs (created by AddonPanel)
in AddonPanel
in Unknown (created by ManagerConsumer)
in ManagerConsumer (created by Panel)
in Panel (created by Layout)
in div (created by Context.Consumer)
in Styled(div) (created by Panel)
in Panel (created by Layout)
in div (created by Context.Consumer)
in Styled(div) (created by Main)
in div (created by Context.Consumer)
in Styled(div) (created by Main)
in Main (created by Layout)
in Layout (created by Context.Consumer)
in WithTheme(Layout) (created by DesktopLayout)
in DesktopLayout (created by App)
in div (created by Context.Consumer)
in Styled(div) (created by App)
in App
in App (created by SizeMeRenderer(Component))
in SizeMeReferenceWrapper (created by SizeMeRenderer(Component))
in SizeMeRenderer(Component) (created by SizeMe(Component))
in SizeMe(Component)
in ThemeProvider
in Unknown (created by ManagerConsumer)
in ManagerConsumer (created by Manager)
in EffectOnMount (created by Manager)
in Manager (created by QueryLocation)
in QueryLocation (created by Main)
in Main (created by Root)
in Router (created by BrowserRouter)
in BrowserRouter (created by Root)
in HelmetProvider (created by Root)
in Root
Environment
Node : 16.13.1
OS : linux x64
npm : 8.1.2
nx : 13.3.0
@nrwl/angular : 13.3.0
@nrwl/cli : 13.3.0
@nrwl/cypress : 13.3.0
@nrwl/devkit : 13.3.0
@nrwl/eslint-plugin-nx : 13.3.0
@nrwl/express : undefined
@nrwl/jest : 13.3.0
@nrwl/linter : 13.3.0
@nrwl/nest : undefined
@nrwl/next : undefined
@nrwl/node : undefined
@nrwl/nx-cloud : undefined
@nrwl/react : undefined
@nrwl/react-native : undefined
@nrwl/schematics : undefined
@nrwl/tao : 13.3.0
@nrwl/web : undefined
@nrwl/workspace : 13.3.0
@nrwl/storybook : 13.3.0
@nrwl/gatsby : undefined
typescript : 4.4.4
rxjs : 7.4.0
---------------------------------------
Community plugins:
@angular/animations: 13.1.0
@angular/common: 13.1.0
@angular/compiler: 13.1.0
@angular/core: 13.1.0
@angular/forms: 13.1.0
@angular/platform-browser: 13.1.0
@angular/platform-browser-dynamic: 13.1.0
@angular/router: 13.1.0
@angular-devkit/build-angular: 13.0.4
@angular/cli: 13.0.4
@angular/compiler-cli: 13.1.0
@angular/language-service: 13.1.0
@storybook/angular: 6.4.5
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 45 (21 by maintainers)
@mandarini as strange as this looks after adding those 2 dependencies my issue si resolved:
The
reactlibrary was not installed butreact-domwas installed. As my investigation went@nrwl/workspaceinstallsreact@17.0.2while the dependency for storybook isreact@16.14.0.Looking into this ppl! 😃
After juggling dependencies back and forth I was able to make it work with followg:
however when I have created brand new workspace and copied the dependencies it was still failing… so I have copied package-lock.json (attached) and after
npm ciit was fixed - from now on I can do justnpm iand all is working fine with abowe dependencies… package-lock.zipIn case it helps someone, my issue was that I had a major version mismatch between
reactandreact-dom. After changing both to version17.0.2the problem was resolved for me.This resolved the issue for me too, thank you!
I’d also like to raise awareness of this unrelated Storybook issue — I encountered it when creating a new workspace for debugging purposes.
It finally works for me. I deleted my
node_modulesandpackage-lock.jsonand performed a clean install. I tested it on my repoduction repo, https://github.com/mandarini/test-nx-story and my actual repository, all of which have slightly different Nx, Angular and Storybook versions, for verification. All of them work now.This fixed it for me:
"react"from package.jsonnpm installThanks @mandarini!
Disclaimer: I first encountered this issue with a new production workspace on 16-12-2021. I’m unable to reproduce this issue today in a test workspace following these same commands. For possible future reference I’ve documented the initial commands I executed (aside from those to install some trivial dependencies).
workspace.json) with Angular and NestJS applications generated later, as follows:nx reportoutput:@mandarini I noticed that the ‘community plugins’ section above lists different versions of Angular packages compared to those listed in
package.json. I’m new to Nx but this seems odd to me. Where doesnx reportget this data from?package.json (partial):
Thank you!
I also confirm that adding devDependency on react and react-dom solved the issue for me! thnx @electrofLy
wowwwww thanks so much @electrofLy !!! that’s a great lead! I’ll look into it!
@mandarini yes it still persist if I use
13.3.6😦 I just tried what other people suggested but that didn’t help.Unfortunately I cannot share the repository and I don’t really have time now to try to create a reproducable repo.
A difference I can see with your repo is that we use
angular.jsonand notworkspace.json+ I had to defineprojectBuildConfigproperty per storybook project in order to make storybook compile again (after updating).We were able to reproduce this in our workshop yesterday as well.
After more poking around. The issue seems to have introduced somewhere after 13.2.4. I can get it storybook to load when backing the version to 13.2.4 with the following script: