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

Story function not found {} undefined #6

Closed
cescoferraro opened this issue Jul 21, 2020 · 20 comments
Closed

Story function not found {} undefined #6

cescoferraro opened this issue Jul 21, 2020 · 20 comments

Comments

@cescoferraro
Copy link

cescoferraro commented Jul 21, 2020

Hi! Thanks for the amzing library.

I am having some issues implementing this on a project I currently working on.

image

// .storybook/src/stories/test.stories.tsx

import React from "react";

export default {
  title: "Storybook Controls",
};

export const controlsStory = ({ disabled, text }) => (
  <button disabled={disabled}>
    {text}
  </button>
);

controlsStory.story = {
  controls: {
    disabled: { type: 'boolean', value: false },
    text: { type: 'text', value: 'Hello Storybook' },
  }
}

module.exports = {
  addons: ['@storybook/addon-docs', '@component-controls/storybook'],
}


// .storybook/config.js

import { configure } from '@storybook/react';
// automatically import all files ending in *.stories.tsx
configure(require.context('./src/stories', true, /\.stories\.tsx?$/), module);


// .storybook/main.js
module.exports = {
  addons: ['@storybook/addon-docs', '@component-controls/storybook'],
}



// .storybook/webpack.config.js

module.exports = ({ config }) => {
  config.module.rules.push({
    test: /\.(ts|tsx)$/,
    loader: require.resolve('babel-loader'),
    options: {
      presets: [require.resolve('babel-preset-react-app')],
    },
  });

  config.resolve.extensions.push('.ts', '.tsx');
  return config;
};

@atanasster
Copy link
Collaborator

Thanks @cescoferraro - what version of storybook are you using? Currently trying the support v6rc.

If possible, i would recommend using the gatsby or nextjs versions becuase of performance reasons: https://component-controls.com/tutorial/getting-started/gatsby

@cescoferraro
Copy link
Author

@atanasster i am using v5. :/
but it is a new next.js project.
was having issues upgrading to v6.
will give it a try again and report back

@atanasster
Copy link
Collaborator

Thanks - pls let me know. In the meantime i will also try to get the v5support up to speed if possible - v6 and v5 are getting further apart unfortunately.

Check my performance article as well, storybook doc sites are not performing very well in production: https://component-controls.com/blogs/gatsby-vs-nextjs-vs-storybook

@cescoferraro
Copy link
Author

image
@atanasster

@cescoferraro
Copy link
Author

but maybe

WARN We found no files matching any of the following globs:
WARN 
WARN ./**/*.stories.(tsx|mdx)
WARN 
WARN Maybe your glob was invalid?
WARN see: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#correct-globs-in-mainjs

@atanasster
Copy link
Collaborator

@cescoferraro - those seem all storybook errors. Do you have all your storybook and associated addons upgraded to 6?

@cescoferraro
Copy link
Author

cescoferraro commented Jul 21, 2020

@atanasster I am not using any addon.
all I am doing is
yarn add --exact --dev @storybook/react@6
Am I missing something?

my main.js looks like

module.exports = {
  stories: ['./**/*.stories.@(ts|tsx)']
}

@cescoferraro
Copy link
Author

running
npx sb@next upgrade --prerelease
leds to the same behaviour

@atanasster
Copy link
Collaborator

@cescoferraro - not sure how it works the way you are installing. For me, I just add "@storybook/react": "next",

On storybook 5, I found the incompatibility with global decorators - they are not exported the way they are exported in v6 and I am trying to find a way to cover both versions. I will post once I have some news. Are you using decorators in your preview.js config file?

Do you have github repo that I can try and make sure everything works?

@atanasster
Copy link
Collaborator

@cescoferraro - I got a workaround for storybook 5 and have downgraded one of my projects to sb5 for testing:

  1. You need to declare all global decorators in a runtime.js configuration file (this is so component-controls can read it in a sb5 environment):
    https://github.com/atanasster/grommet-controls/blob/master/.storybook/runtime.js

  2. link to live site https://atanasster.github.io/grommet-controls/?path=/page/controls-controls-avatar--main

@atanasster
Copy link
Collaborator

I uploaded a screencast on youtube, with proof it's under storybook 5 :)

https://twitter.com/atanasster/status/1285735535365980169

@atanasster
Copy link
Collaborator

@cescoferraro - I looked again at your initial post and it seems I have overcomplicated the issue with global decorators etc. Sorry about that - I was running errands during the day and It turns out just some of your storybook setups were a bit older-style ie require. context style loading of stories, which is not supported by component-controls. Also, you don't need the addon-docs if you are using component-controls.

So here is a repo with storybook 5 that roughly replicates your setup from the initial post: https://github.com/atanasster/storybook-5-controls-starter
Live demo: https://storybook-5-controls-starter.netlify.app/?path=/page/storybook-controls--controls-story

component-controls

@cescoferraro
Copy link
Author

cescoferraro commented Jul 22, 2020

@atanasster I finally managed to upgrade do version 6
but rc13 breaks things for me. i got it to work with rc0.
but did not really try anything else.

anyways, the storybook get stuck somewhy. https://5f17c105f82a080022345e52-vobmerjtwh.chromatic.com/?path=/story/checkoutpagelayout--full-checkout-cart

will try downgrading to version 5. and use the same config as your starter

@atanasster
Copy link
Collaborator

@cescoferraro the v6 rc are not very stable for me either. Also 6 is so far a bit slower than 5.

Let me know your progress so i can close this issue as soon as you are set up.

@cescoferraro
Copy link
Author

@atanasster YAY! its working now!

@cescoferraro
Copy link
Author

@atanasster one more thing.
where can I find docs about the the controls I can use

@cescoferraro
Copy link
Author

is the a image field? it would be so cool if I could randomize the images on my components

@cescoferraro
Copy link
Author

thanks for your support @atanasster

@atanasster
Copy link
Collaborator

Yes you can randomize images - check the video on my twitter post.

Here is a post on controls and it has sole more links inside https://component-controls.com/blogs/introduction-to-controls

Documentation is still wip so let me know if you miss some info - create a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants