Skip to content
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

Cannot read property 'preference' of undefined inside Storybook #69

Closed
ManUtopiK opened this issue Feb 8, 2021 · 13 comments · Fixed by #99
Closed

Cannot read property 'preference' of undefined inside Storybook #69

ManUtopiK opened this issue Feb 8, 2021 · 13 comments · Fixed by #99
Labels
bug Something isn't working

Comments

@ManUtopiK
Copy link

Version

@nuxtjs/color-mode: ^2.0.3
nuxt: ^2.14.12
@nuxtjs/storybook: ^3.3.1

Steps to reproduce

Install nuxt with @nuxtjs/color-mode and @nuxtjs/storybook.

What is actually happening?

I run nuxt as target: static. Everything works fine with yarn dev.
I can launch Storybook and got it at localhost:3003, but inside the main frame of Storybook, there is this error:
Cannot read property 'preference' of undefined.

I tried everything related in #21 and #25 without success...

@ManUtopiK ManUtopiK added the bug Something isn't working label Feb 8, 2021
Copy link
Contributor

Atinux commented Feb 8, 2021

@farnabaz do you mind checking when you have 5 min?

@ManUtopiK
Copy link
Author

I think I just fixed this issue, but I made many change on the storybook config, so I'm not sure how I did...
I set a custom storybook config as explained here.

But maybe it's work just only with this file .storybook/preview-head.html:

<script>
  var data = {}
  window['__NUXT_COLOR_MODE__'] = {
    preference: 'light',
  }
</script>

@farnabaz
Copy link
Collaborator

@nuxtjs/storybook executes plugin scripts after the plugin import and this cause the issue. And color-mode uses global variable on import. The leads to undefined error.

@kgnfth
Copy link

kgnfth commented May 20, 2021

@Atinux i have the same issue after upgrading from 2.0.5 to 2.0.7

my settings is
nuxt.config.js

colorMode: {
  storageKey: 'color-mode',
  preference: 'system',
  fallback: 'dark',
  classSuffix: '',
}

and in my tailwind.config.js i have

darkMode: 'class'

Copy link
Contributor

Atinux commented May 20, 2021

Hi @kgnfth

Please use 2.0.8, small mistake sorry about this.

@kgnfth
Copy link

kgnfth commented May 20, 2021

Hi @kgnfth

Please use 2.0.8, small mistake sorry about this.

Thx it works 💙

@Atinux Atinux closed this as completed Jun 11, 2021
@BennaceurHichem
Copy link

I'm having the same problem, I used the 2.0.8 version but the error still occurs in Storybook, any idea?

Copy link
Contributor

Atinux commented Jun 13, 2021

Did you try the 2.0.10?

@BennaceurHichem
Copy link

Yes I did, I was workinf with 2.0.10, then I downgrade and same thing. This error was gone when I applied what @ManUtopiK mention

@khawarizmus
Copy link

khawarizmus commented Jun 13, 2021

@Atinux is there a cleaner way as to not have to eject and keep using the module way of doing things with nuxtjs? while the solution provided by @ManUtopiK works it forces us to have the config in the .storybook folder.

Copy link
Contributor

Atinux commented Jun 14, 2021

Cc @farnabaz

@farnabaz
Copy link
Collaborator

@gimyboya Using color-mode@v2.0.8 + nuxt-storybook > 4.0.0 should work without any issues.

New versions of module is not compatible with Storybook because it uses vue-renderer hook to inject script and nuxt-storybook does not support renderer hooks. https://github.com/nuxt-community/color-mode-module/blob/master/lib/module.js#L31

Copy link
Contributor

Atinux commented Jun 14, 2021

cc @danielroe on it too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants