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

source-loader: TypeError: Cannot read property 'query' of undefined #11965

Closed
petermikitsh opened this issue Aug 13, 2020 · 1 comment
Closed

Comments

@petermikitsh
Copy link
Contributor

Describe the bug

An auto-generated storybook with @storybook/source-loader prints this error message and sources do not load, and no 'Story' tab appears.

To Reproduce

Demo Repo: https://github.com/petermikitsh/sb-source-error (just run yarn start-storybook)

Steps to reproduce the behavior:

npx init storybook # choose react
npm i @storybook/source-loader --dev

.storybook/main.js:

module.exports = {
  stories: [
    "../stories/**/*.stories.mdx",
    "../stories/**/*.stories.@(js|jsx|ts|tsx)",
  ],
  addons: [
    "@storybook/addon-links",
    "@storybook/addon-essentials",
+    "@storybook/source-loader",
  ],
+  webpackFinal: async (config) => {
+    config.module.rules = [
+      ...config.module.rules,
+      {
+        test: /\.stories\.jsx?$/,
+        loaders: [
+          {
+            loader: require.resolve("@storybook/source-loader"),
+            options: { parser: "javascript" },
+          },
+        ],
+        enforce: "pre",
+      },
+    ];
+    return config;
+  },
};
info @storybook/react v6.0.5
info 
info => Loading presets
WARN   Failed to load preset: {"name":"@storybook/source-loader","type":"presets"} on level 1
ERR! TypeError: Cannot read property 'query' of undefined
ERR!     at getOptions (/[REDACTED]/node_modules/loader-utils/lib/getOptions.js:6:31)
ERR!     at readAsObject (/[REDACTED]/node_modules/@storybook/source-loader/dist/dependencies-lookup/readAsObject.js:25:45)

Expected behavior

No error, story source code loads.

Screenshots

Screen Shot 2020-08-12 at 9 06 38 PM

@petermikitsh
Copy link
Contributor Author

My apologies-- I may have mis-read the documentation. I think my configuration listed above is incorrect. I've since updated my configuration. Most of my stories are now populating with source code.

Addons should be something like:

  addons: [
    "@storybook/addon-links",
    "@storybook/addon-essentials",
+   "@storybook/addon-storysource",
  ],

@storybook/addon-storysource uses @storybook/source-loader under the hood. If you're overriding webpack configs (e.g defining your own config.module.rules array, you'll need to setup @storybook/source-loader yourself.

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