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

addon-storysource would throw compile error 'addSourceDecorator is not a function' when import after named export #9490

Closed
jackysee opened this issue Jan 16, 2020 · 1 comment

Comments

@jackysee
Copy link

Describe the bug
When writing story in CSF with import statement appear after first named export, it will throw compile error.

To Reproduce
Steps to reproduce the behavior:

  1. Clone the demo repo https://github.com/jackysee/storysource-order
  2. npm install and npm run storybook
  3. Open browser http://localhost:6006
  4. See error

Expected behavior
It should compile fine. When @storybook/addon-storysource is not installed, the stories can be compiled and shown correctly.

Screenshots
image

TypeError: addSourceDecorator is not a function
    at Module../src/components/MyButton.stories.js (http://localhost:6006/main.da02c91890c0d533134b.bundle.js:245:14)
    at __webpack_require__ (http://localhost:6006/runtime~main.da02c91890c0d533134b.bundle.js:786:30)
    at fn (http://localhost:6006/runtime~main.da02c91890c0d533134b.bundle.js:151:20)
    at webpackContext (http://localhost:6006/main.da02c91890c0d533134b.bundle.js:95:9)
    at http://localhost:6006/vendors~main.da02c91890c0d533134b.bundle.js:4727:31
    at Array.forEach (<anonymous>)
    at http://localhost:6006/vendors~main.da02c91890c0d533134b.bundle.js:4726:22
    at Array.forEach (<anonymous>)
    at http://localhost:6006/vendors~main.da02c91890c0d533134b.bundle.js:4725:14
    at render (http://localhost:6006/vendors~main.da02c91890c0d533134b.bundle.js:1897:13)

Code snippets

export default { title: "MyButton" };

import MyButton from "./MyButton.vue";
export const button = () => ({
  components: { MyButton },
  template: `<MyButton>Hi</MyButton>`
});

import Icon from "./Icon.vue";
export const WithIcon = () => ({
  components: { MyButton, Icon },
  template: `<MyButton><Icon/>Hello</MyButton>`
});

System:

Environment Info:

  System:
    OS: Linux 4.4 Ubuntu 18.04.3 LTS (Bionic Beaver)
    CPU: (4) x64 Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz
  Binaries:
    Node: 12.13.0 - /tmp/fnm-shell-3449273/bin/node
    Yarn: 1.16.0 - /mnt/c/Users/jackys/scoop/apps/nvm/current/nodejs/nodejs/yarn
    npm: 6.13.6 - /tmp/fnm-shell-3449273/bin/npm
  npmPackages:
    @storybook/addon-actions: ^5.3.4 => 5.3.4
    @storybook/addon-links: ^5.3.4 => 5.3.4
    @storybook/addon-storysource: ^5.3.4 => 5.3.4
    @storybook/addons: ^5.3.4 => 5.3.4
    @storybook/vue: ^5.3.4 => 5.3.4

Additional context
The source as seen in devtools, you can see the addSourceDecorator is put lower than the calling code.

export default {parameters: {"storySource":{"source":"export default { title: \"MyButton\" };\n\nimport MyButton from \"./MyButton.vue\";\n\nexport const button = () => ({\n  components: { MyButton },\n  template: `<MyButton>Hi</MyButton>`\n});\n\nimport Icon from \"./Icon.vue\";\nexport const WithIcon = () => ({\n  components: { MyButton, Icon },\n  template: `<MyButton><Icon/>Hello</MyButton>`\n});\n","locationsMap":{"mybutton--button":{"startLoc":{"col":22,"line":5},"endLoc":{"col":2,"line":8},"startBody":{"col":22,"line":5},"endBody":{"col":2,"line":8}},"mybutton--with-icon":{"startLoc":{"col":24,"line":11},"endLoc":{"col":2,"line":14},"startBody":{"col":24,"line":11},"endBody":{"col":2,"line":14}}}},}, title: "MyButton" };

import MyButton from "./MyButton.vue";

export const button = addSourceDecorator(() => ({
  components: { MyButton },
  template: `<MyButton>Hi</MyButton>`
}), {__STORY__, __ADDS_MAP__,__MAIN_FILE_LOCATION__,__MODULE_DEPENDENCIES__,__LOCAL_DEPENDENCIES__,__SOURCE_PREFIX__,__IDS_TO_FRAMEWORKS__});;

import Icon from "./Icon.vue";

/* eslint-disable */
// @ts-ignore
var withSourceLoader = require('@storybook/source-loader/preview').withSource;
// @ts-ignore
var addSourceDecorator = require("@storybook/source-loader/preview").addSource;
// @ts-ignore
var __SOURCE_PREFIX__ = "/home/jackys/works/storybook/storysource-order/src/components";
// @ts-ignore
var __STORY__ = "export default { title: \"MyButton\" };\n\nimport MyButton from \"./MyButton.vue\";\n\nexport const button = () => ({\n  components: { MyButton },\n  template: `<MyButton>Hi</MyButton>`\n});\n\nimport Icon from \"./Icon.vue\";\nexport const WithIcon = () => ({\n  components: { MyButton, Icon },\n  template: `<MyButton><Icon/>Hello</MyButton>`\n});\n";
// @ts-ignore
var __ADDS_MAP__ = {"mybutton--button":{"startLoc":{"col":22,"line":5},"endLoc":{"col":2,"line":8},"startBody":{"col":22,"line":5},"endBody":{"col":2,"line":8}},"mybutton--with-icon":{"startLoc":{"col":24,"line":11},"endLoc":{"col":2,"line":14},"startBody":{"col":24,"line":11},"endBody":{"col":2,"line":14}}};
// @ts-ignore
var __MAIN_FILE_LOCATION__ = "/MyButton.stories.js";
// @ts-ignore
var __MODULE_DEPENDENCIES__ = [];
// @ts-ignore
var __LOCAL_DEPENDENCIES__ = {};
// @ts-ignore
var __IDS_TO_FRAMEWORKS__ = {};
        

export const WithIcon = addSourceDecorator(() => ({
  components: { MyButton, Icon },
  template: `<MyButton><Icon/>Hello</MyButton>`
}), {__STORY__, __ADDS_MAP__,__MAIN_FILE_LOCATION__,__MODULE_DEPENDENCIES__,__LOCAL_DEPENDENCIES__,__SOURCE_PREFIX__,__IDS_TO_FRAMEWORKS__});

@shilman
Copy link
Member

shilman commented Jan 16, 2020

Shiver me timbers!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.3.5 containing PR #9492 that references this issue. Upgrade today to try it out!

Closing this issue. Please re-open if you think there's still more to do.

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

No branches or pull requests

2 participants