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.

Yarn workspace @storybook/react not hoisted

See original GitHub issue

Describe the bug I have a yarn workspace project. Running yarn workspace x storybook yields this error:

ERROR in ../node_modules/@storybook/addon-docs/dist/frameworks/react/config.js
Module not found: Error: Can't resolve '@storybook/react' in '/home/root_project_path/node_modules/@storybook/addon-docs/dist/frameworks/react'
 @ ../node_modules/@storybook/addon-docs/dist/frameworks/react/config.js 3:13-40
 @ ../node_modules/@storybook/addon-docs/react/config.js
 @ multi ../node_modules/@storybook/core/dist/server/common/polyfills.js ../node_modules/@storybook/core/dist/server/preview/globals.js ../node_modules/@storybook/addon-docs/dist/frameworks/common/../../../react/config.js ./.storybook/config.js ../node_modules/webpack-hot-middleware/client.js?reload=true&quiet=true

I am not too familiar with how Yarn decides what packages to hoist. I have everything except @storybook/react hoisted to my root folder.

What I have under my workspace x is like so:

node_modules
β”œβ”€β”€ @babel
β”‚Β Β  β”œβ”€β”€ core
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ lib
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ config
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ files
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ helpers
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── validation
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ tools
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── transformation
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ file
β”‚Β Β  β”‚Β Β  β”‚Β Β      └── util
β”‚Β Β  β”‚Β Β  └── node_modules
β”‚Β Β  β”œβ”€β”€ plugin-syntax-flow
β”‚Β Β  β”‚Β Β  └── lib
β”‚Β Β  β”œβ”€β”€ plugin-transform-flow-strip-types
β”‚Β Β  β”‚Β Β  └── lib
β”‚Β Β  β”œβ”€β”€ plugin-transform-react-constant-elements
β”‚Β Β  β”‚Β Β  └── lib
β”‚Β Β  └── preset-flow
β”‚Β Β      └── lib
β”œβ”€β”€ babel-plugin-named-asset-import
β”œβ”€β”€ debug
β”‚Β Β  β”œβ”€β”€ dist
β”‚Β Β  └── src
β”œβ”€β”€ ms
β”œβ”€β”€ source-map
β”‚Β Β  β”œβ”€β”€ dist
β”‚Β Β  └── lib
└── @storybook
    └── react
        β”œβ”€β”€ bin
        β”œβ”€β”€ dist
        β”‚Β Β  β”œβ”€β”€ client
        β”‚Β Β  β”‚Β Β  └── preview
        β”‚Β Β  β”œβ”€β”€ demo
        β”‚Β Β  └── server
        └── node_modules
            └── semver
                └── bin

To Reproduce Steps to reproduce the behavior:

  1. Initialize storybook react under a yarn workspace x
  2. yarn workspace x storybook

Expected behavior Runs without error

System:

Environment Info:

  System:
    OS: Linux 5.0 Ubuntu 18.04.3 LTS (Bionic Beaver)
    CPU: (4) x64 Intel(R) Core(TM) i7-6500U CPU @ 2.50GHz
  Binaries:
    Node: 12.14.0 - /usr/bin/node
    Yarn: 1.21.1 - /usr/bin/yarn
    npm: 6.13.4 - /usr/bin/npm
  Browsers:
    Chrome: 79.0.3945.88
    Firefox: 71.0
  npmPackages:
    @storybook/react: ^5.2.8 => 5.2.8 
  npmGlobalPackages:
    @storybook/cli: 5.2.8

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
raroulcommented, Mar 20, 2020

It seems that there is a bug with @storybook/react and workspaces. A workaround could be to disable hoisting for storybook in the root package.json of your workspace. No more errors after that for me.

More infos here: https://classic.yarnpkg.com/blog/2018/02/15/nohoist/

{
  "private": true,
  "workspaces": {
    "packages": [
      "*"
    ],
    "nohoist": [
      "@storybook",
      "**/@storybook",
      "**/@storybook/**"
    ]
  }
}
2reactions
shilmancommented, Mar 21, 2020

@raroul there are bunch of yarn 2 related fixes that @gaetanmaisse has been working on, available in 6.0. hopefully these will make the workaround unnecessaruy.

Read more comments on GitHub >

github_iconTop Results From Across the Web

nohoist in Workspaces | Yarn Blog
nohoist patterns. β€œ**/react-native”: this tells yarn not to hoist the react-native package itself, no matter where it is. (shallow).
Read more >
reactjs - How to figure out why package is not hoisted in yarn3 ...
I'm using yarn 3 monorepo and for some reason, react-dom package is not hoisted properly: The same version of react-dom is duplicated acrossΒ ......
Read more >
The Case for Monorepos: A sane Workspace Setup (Part 2)
Learn how to setup dev tooling in a monorepo, run tasks efficiently, release multiple packages and overcome common DevOps challenges.
Read more >
A guide through The Wild Wild West of setting up a mono repo ...
Setting up a mono repo from scratch. We will be using TypeScript, Yarn workspaces, Lerna, and Jest. The release of the packages will...
Read more >
Today I Learned: Lerna and Yarn Workspaces - Julian Burr
Popular examples for the use of monorepos (and yarn workspaces) are React, Babel, Storybook and a lot of others. Yarn workspaces helps you...
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