question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request: Support For Stories Distributed Amongst Lerna Packages

See original GitHub issue

Is your feature request related to a problem? Please describe. At present Storybook will not work with stories distributed amongst packages in a monorepo. Storybook’s babel loader assumes that it only needs to transpile js within src, so if you use a configuration that looks for stories outside of ./src that are not transpiled, for example:

const req = require.context('../../../packages', true, /.stories.js$/)

Loading these (untranspiled) stories results in errors such as:

ERROR in ../components/src/components/nav/LinkList/LinkList.js 9:2
Module parse failed: Unexpected token (9:2)
You may need an appropriate loader to handle this file type.

This is because it is encountering JSX in files that are outside of src that are not transpiled and is choking on them.

Describe the solution you’d like It would be great if Storybook offered a config option to specify which directories it should load using babel-loader.

Describe alternatives you’ve considered There is a generic solution for create-react-apps here

Are you able to assist bring the feature to reality? maybe

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
hipstersmoothiecommented, Nov 30, 2018

This should work. I have a storybook that loads stories from another monorepo package. Try adding this to your storybook webpack config. Find the babel rule in loaders and modify the include and exclude to include the parent directory (for a monorepo this will be packages).

module.exports = (baseConfig, env, config) => {
  // Find Babel Loader
  const babelRules = config.module.rules.filter(rule => {
    let isBabelLoader = false;

    if (rule.loader && rule.loader.includes('babel-loader')) {
      isBabelLoader = true;
    }

    if (rule.use) {
      rule.use.forEach(use => {
        if (typeof use === 'string' && use.includes('babel-loader')) {
          isBabelLoader = true;
        } else if (
          typeof use === 'object' &&
          use.loader &&
          use.loader.includes('babel-loader')
        ) {
          isBabelLoader = true;
        }
      });
    }

    return isBabelLoader;
  });

  babelRules.forEach(rule => {
    rule.include = /../;
    rule.exclude = /node_modules/;
  });
  
  return config;
};

Let me know if it helps you!

0reactions
earGOcommented, Jul 22, 2019

this

This should work. I have a storybook that loads stories from another monorepo package. Try adding this to your storybook webpack config. Find the babel rule in loaders and modify the include and exclude to include the parent directory (for a monorepo this will be packages).

module.exports = (baseConfig, env, config) => {
  // Find Babel Loader
  const babelRules = config.module.rules.filter(rule => {
    let isBabelLoader = false;

    if (rule.loader && rule.loader.includes('babel-loader')) {
      isBabelLoader = true;
    }

    if (rule.use) {
      rule.use.forEach(use => {
        if (typeof use === 'string' && use.includes('babel-loader')) {
          isBabelLoader = true;
        } else if (
          typeof use === 'object' &&
          use.loader &&
          use.loader.includes('babel-loader')
        ) {
          isBabelLoader = true;
        }
      });
    }

    return isBabelLoader;
  });

  babelRules.forEach(rule => {
    rule.include = /../;
    rule.exclude = /node_modules/;
  });
  
  return config;
};

Let me know if it helps you!

This one helped with local storybooks while importing components from other packages. Thank you!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lerna Distributed Task Execution (DTE) Example/Benchmark
This repo enables Distributed Task Execution using Nx Cloud, which means that lerna run commands would run on multiple agents. It doesn't require...
Read more >
Lerna: Documentation
Lerna is a fast modern build system for managing and publishing multiple JavaScript/TypeScript packages from the same repository.
Read more >
Sharing reusable Vue.js components with Lerna, Storybook ...
Lerna will be used to keep all our components inside the same repository (monorepos) with independent versions, Storybook to create and visualize components...
Read more >
5 Practical Ways To Share Code: From NPM to Lerna And Bit
5 practical ways to share code between projects and repositories, from NPM to Lerna and Bit. The best ways to share code and...
Read more >
How to Efficiently Manage JavaScript Monorepos With Lerna
Lerna is a fast modern build system for managing and publishing multiple JavaScript/TypeScript packages from the same repository.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found