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

[Bug]: difficulties upgrading @storybook/html to 7.0 using npx sb upgrade and main.cjs/.js in rush monorepo web components project #22219

Closed
1 of 2 tasks
usrrname opened this issue Apr 23, 2023 · 6 comments

Comments

@usrrname
Copy link
Contributor

usrrname commented Apr 23, 2023

Describe the bug

This bug report shows 2 approaches I took in attempting to upgrade @storybook/html and storybook-addons to 7.0 within an enterprise rush monorepo.

Repro 1, 2 , 3 demonstrate cli issues with npx sb ugrade, npx sb automigrate and pnpm dlx storybook upgrade, and end with the discovery of compatibility errors between web component project setup and Storybook config files support of ESM.

I'm not expecting this to go anywhere since my stack isn't common, just logging it as I'm confused about what to do to move ahead with migration due to:

  1. inability to use npm or yarn in a rush monorepo, (partially solved by pnpm dlx...)
  2. inability to change my current setup from main.cjs to use a main.ts because this project needs to bundle ESM and CommonJS packages, thus facing required is not defined Related: Webpack5 + type: module = require is not defined #14877 [Bug]: Critical dependency: require function is used in a way in which dependencies cannot be statically extracted. #21316
  3. inability to render FAST component [slotted] templates in CSF3 👈🏼 What I'm investigating

Any advice is appreciated 🙏🏼

Reproductions

TODO:

  • @storybook/web-components-vite spike with FAST component / template rendering
  • @storybook/web-components-webpack5 spike with FAST components / template rendering

Reproduction 1: usingnpx sb upgrade

  1. Inside a rush monorepo, cd into a project
  2. At the project root, run npx sb upgrade
  3. At first everything looks as if updating..

1

Then, a workspace linking dependency (linking current project to a neighboring svg library project as dependency) kills the upgrade process 🤨

2

  1. In the package.json, most SB packages appear upgraded...

I manually upgrade "@storybook/builder-webpack5": "6.5.9" to "7.0.6" using rushx add -p @storybook/builder-webpack5@latest --dev

  1. Tried running Storybook locally by running rushx start-storybook (this command aliases the build command and the storybook start command. node common/scripts/install-run-rushx.js start-storybook)

I get the following error that seems to indicate the temporary files are still referencing the previous version of @storybook/html

Error 🔴
Found configuration in /Users/jenc/my-project-name/rush.json

Rush Multi-Project Build Tool 5.62.2 - Node.js 16.17.1 (LTS)

node:internal/modules/cjs/loader:959
  throw err;
  ^

Error: Cannot find module '/Users/jenc/my-project-name/common/temp/node_modules/.pnpm/@[email protected]_b430b66b36028ee449ae83ff4342ba80/node_modules/@storybook/html/bin/index.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
    at Function.Module._load (node:internal/modules/cjs/loader:804:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
  1. I run rush purge to delete all dependencies and cache builds,
    rush update to install the whole monorepo's dependencies, followed by rush build to incrementally rebuild all projects successfully

  2. Detour: I try to start sb locally with rushx start-storybook and come across this error 👇🏼

Error 🔴
```
Found configuration in /Users/a6121363/FECoE_central/rush.json
...
sh: start-storybook: command not found
The script failed with exit code 127
```

Realizing the build script for start-storybook has changed, I manually replace all package.json script commands with storybook dev and storybook build

  1. I'm able to start Storybook locally despite encountering a broken build where the iframe says required is not defined Webpack5 + type: module = require is not defined #14877 or [Bug]: Module not found: Error: Can't resolve 'uuid-browser/v4' #21916 due to using a main.cjs and package.json having type:module

module-not-found

Screenshot 2023-04-23 at 10 21 07 PM

Reproduction 2: systematic manual attempts at upgrading

  1. Install dependencies with rush add
rush add -p @storybook/cli@latest @storybook@latest @storybook/addons-essentials@latest @storybook/addon-highlight @storybook/addon-controls@latest  @storybook/addons-links@latest @storybook/addon-backgrounds --dev
  1. I run rushx start-storybook to start storybook locally and am met with [Bug]: Module not found: Error: Can't resolve 'uuid-browser/v4' #21916 (even if I change config files to main.ts). Update: Maintainer has fixed. Patch release is in the works but I continue to see the require is not defined error.

image

  1. Attempted to use npx sb automigrate to see if this would resolve any errors. While dependency installs and removal of builder/manager-webpack5 were successful, this didn't allow building Storybook locally.

Screenshot 2023-04-23 at 10 21 07 PM

Reproduction 3: using pnpm dlx storybook upgrade

Similar break on workspace: workspace-reference-to-neighboring-project-dependency

Error 🔴
../../../../Library/pnpm/store/v3/tmp/dlx-9046/node_modules/.pnpm/[email protected]/no../../../../Library/pnpm/store/v3/tmp/dlx-9046/node_modules/.pnpm/[email protected]/node_modules/esbuild: Running postinstall script, done in 304ms
 • Checking for latest versions of '@storybook/*' packagesinfo ,Upgrading /Users/a6121363/FECoE_central/saffron/libs/core-components/package.json
info 
info  @storybook/addon-a11y                          ^6.4.19  →   ^7.0.7
info  @storybook/addon-actions                       ^6.4.19  →   ^7.0.7
info  @storybook/addon-backgrounds                   ^6.4.19  →   ^7.0.7
info  @storybook/addon-controls                      ^6.4.19  →   ^7.0.7
info  @storybook/addon-docs                          ^6.4.19  →   ^7.0.7
info  @storybook/addon-essentials                    ^6.4.19  →   ^7.0.7
info  @storybook/addon-highlight              ^7.0.0-alpha.7  →   ^7.0.7
info  @storybook/addon-interactions                  ~6.5.10  →   ~7.0.7
info  @storybook/addon-links                         ^6.4.19  →   ^7.0.7
info  @storybook/builder-webpack5                    ^6.4.19  →   ^7.0.7
info  @storybook/cli                                 ^6.5.10  →   ^7.0.7
info  @storybook/csf                 0.0.2--canary.4566f4d.1  →    0.1.0
info  @storybook/html                                  6.5.9  →    7.0.7
info  @storybook/manager-webpack5                    ^6.4.19  →  ^6.5.16
info  @storybook/mdx2-csf                             ^0.0.3  →   ^1.0.0
info  @storybook/theming                             ^6.4.19  →   ^7.0.7
info  storybook-multilevel-sort                       ^1.1.0  →   ^1.2.0
info 
info Run npm install to install new versions.
info ,
info 
info ,Upgrading /Users/a6121363/FECoE_central/saffron/libs/core-components/package.json
info 
info No dependencies.
info ,
 • Installing upgrades • Preparing to install dependencies. ✓

 • Installing dependencies(⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂) ⠼ reify: timing arborist:ctor Complet
npm ERR! code EUNSUPPORTEDPROTOCOL
npm ERR! Unsupported URL Type "workspace:": workspace:^1.2.0

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/a6121363/.npm/_logs/2023-04-24T14_03_08_789Z-debug-0.log
. ✖

     An error occurred while installing dependencies.
ERR! Error
ERR!     at NPMProxy.installDependencies (/Users/a6121363/Library/pnpm/store/v3/tmp/dlx-9046/node_modules/.pnpm/@[email protected]/node_modules/@storybook/cli/dist/generate.js:36:2040)
ERR!     at doUpgrade (/Users/a6121363/Library/pnpm/store/v3/tmp/dlx-9046/node_modules/.pnpm/@[email protected]/node_modules/@storybook/cli/dist/generate.js:394:2783)
ERR!     at async withTelemetry (/Users/a6121363/Library/pnpm/store/v3/tmp/dlx-9046/node_modules/.pnpm/@[email protected]/node_modules/@storybook/core-server/dist/index.js:35:3422)
ERR!     at async upgrade (/Users/a6121363/Library/pnpm/store/v3/tmp/dlx-9046/node_modules/.pnpm/@[email protected]/node_modules/@storybook/cli/dist/generate.js:394:3336)
ERR!  HandledError
ERR!     at NPMProxy.installDependencies (/Users/a6121363/Library/pnpm/store/v3/tmp/dlx-9046/node_modules/.pnpm/@[email protected]/node_modules/@storybook/cli/dist/generate.js:36:2040)
ERR!     at doUpgrade (/Users/a6121363/Library/pnpm/store/v3/tmp/dlx-9046/node_modules/.pnpm/@[email protected]/node_modules/@storybook/cli/dist/generate.js:394:2783)
ERR!     at async withTelemetry (/Users/a6121363/Library/pnpm/store/v3/tmp/dlx-9046/node_modules/.pnpm/@[email protected]/node_modules/@storybook/core-server/dist/index.js:35:3422)
ERR!     at async upgrade (/Users/a6121363/Library/pnpm/store/v3/tmp/dlx-9046/node_modules/.pnpm/@[email protected]/node_modules/@storybook/cli/dist/generate.js:394:3336) {
ERR!   handled: true,
ERR!   cause: Error
ERR!       at NPMProxy.executeCommand (/Users/a6121363/Library/pnpm/store/v3/tmp/dlx-9046/node_modules/.pnpm/@[email protected]/node_modules/@storybook/cli/dist/generate.js:39:1699)
ERR!       at NPMProxy.runInstall (/Users/a6121363/Library/pnpm/store/v3/tmp/dlx-9046/node_modules/.pnpm/@[email protected]/node_modules/@storybook/cli/dist/generate.js:39:2695)
ERR!       at NPMProxy.installDependencies (/Users/a6121363/Library/pnpm/store/v3/tmp/dlx-9046/node_modules/.pnpm/@[email protected]/node_modules/@storybook/cli/dist/generate.js:36:1955)
ERR!       at doUpgrade (/Users/a6121363/Library/pnpm/store/v3/tmp/dlx-9046/node_modules/.pnpm/@[email protected]/node_modules/@storybook/cli/dist/generate.js:394:2783)
ERR!       at async withTelemetry (/Users/a6121363/Library/pnpm/store/v3/tmp/dlx-9046/node_modules/.pnpm/@[email protected]/node_modules/@storybook/core-server/dist/index.js:35:3422)
ERR!       at async upgrade (/Users/a6121363/Library/pnpm/store/v3/tmp/dlx-9046/node_modules/.pnpm/@[email protected]/node_modules/@storybook/cli/dist/generate.js:394:3336)
ERR! }

attention => Storybook now collects completely anonymous telemetry regarding usage.
This information is used to shape Storybook's roadmap and prioritize features.
You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
https://storybook.js.org/telemetry

 ERROR  Command failed with exit code 1: storybook upgrade

pnpm: Command failed with exit code 1: storybook upgrade
    at makeError (/usr/local/Cellar/pnpm/8.3.1/libexec/dist/pnpm.cjs:24230:17)
    at handlePromise (/usr/local/Cellar/pnpm/8.3.1/libexec/dist/pnpm.cjs:24801:33)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.handler [as dlx] (/usr/local/Cellar/pnpm/8.3.1/libexec/dist/pnpm.cjs:206754:7)
    at async /usr/local/Cellar/pnpm/8.3.1/libexec/dist/pnpm.cjs:216086:21
    at async main (/usr/local/Cellar/pnpm/8.3.1/libexec/dist/pnpm.cjs:216053:34)
    at async runPnpm (/usr/local/Cellar/pnpm/8.3.1/libexec/dist/pnpm.cjs:216308:5)
    at async /usr/local/Cellar/pnpm/8.3.1/libexec/dist/pnpm.cjs:216300:7

Code Reproduction

Stackblitz of trying to install storybook/html-webpack5 on a node/FAST project where similar errors appear 👇🏼 :
https://stackblitz.com/edit/fast-storybook-webpack

System

Before upgrade
Environment Info:

  System:
    OS: macOS 13.3
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  Binaries:
    Node: 16.17.1 - ~/.nvm/versions/node/v16.17.1/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 8.15.0 - ~/.nvm/versions/node/v16.17.1/bin/npm
  Browsers:
    Chrome: 112.0.5615.137
    Safari: 16.4
  npmPackages:
    @storybook/addon-a11y: ^6.4.19 => 6.5.16 
    @storybook/addon-actions: ^6.4.19 => 6.5.16 
    @storybook/addon-backgrounds: ^6.4.19 => 6.5.16 
    @storybook/addon-controls: ^6.4.19 => 6.5.16 
    @storybook/addon-docs: ^6.4.19 => 6.5.16 
    @storybook/addon-essentials: ^6.4.19 => 6.5.16 
    @storybook/addon-highlight: ^7.0.0-alpha.7 => 7.0.0-alpha.7 
    @storybook/addon-interactions: ~6.5.10 => 6.5.16 
    @storybook/addon-links: ^6.4.19 => 6.5.16 
    @storybook/builder-webpack5: ^6.4.19 => 6.5.16 
    @storybook/cli: ^6.5.10 => 6.5.16 
    @storybook/csf: 0.0.2--canary.4566f4d.1 => 0.0.2--canary.4566f4d.1 
    @storybook/html: 6.5.9 => 6.5.9 
    @storybook/manager-webpack5: ^6.4.19 => 6.5.16 
    @storybook/mdx2-csf: ^0.0.3 => 0.0.3 
    @storybook/theming: ^6.4.19 => 6.5.16 
After upgrade
Environment Info:
  System:
    OS: macOS 13.3
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  Binaries:
    Node: 16.17.1 - ~/.nvm/versions/node/v16.17.1/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 8.15.0 - ~/.nvm/versions/node/v16.17.1/bin/npm
  Browsers:
    Chrome: 112.0.5615.137
    Safari: 16.4
  npmPackages:
    @storybook/addon-a11y: ^7.0.6 => 7.0.6 
    @storybook/addon-actions: ~7.0.6 => 7.0.6 
    @storybook/addon-backgrounds: ^7.0.6 => 7.0.6 
    @storybook/addon-controls: ^7.0.6 => 7.0.6 
    @storybook/addon-docs: ^7.0.6 => 7.0.6 
    @storybook/addon-essentials: ^7.0.6 => 7.0.6 
    @storybook/addon-highlight: ^7.0.6 => 7.0.6 
    @storybook/addon-interactions: ~7.0.6 => 7.0.6 
    @storybook/addon-links: ^7.0.6 => 7.0.6 
    @storybook/cli: ^7.0.6 => 7.0.6 
    @storybook/csf: 0.1.0 => 0.1.0 
    @storybook/html: ~7.0.6 => 7.0.6 
    @storybook/html-webpack5: ~7.0.6 => 7.0.6 
    @storybook/manager-webpack5: ~6.5.16 => 6.5.16 
    @storybook/mdx2-csf: ^1.0.0 => 1.0.0 
    @storybook/theming: ^7.0.6 => 7.0.6 
    @storybook/types: ~7.0.6 => 7.0.6

Additional context

I'm working in a multi-project monorepo with FAST design web components that uses rush as a package manager/monorepo management tool.

Related OSS issues

microsoft/fast#6698
#18351

About Rush

rush uses pnpm under the hood to update a global and project based dependencies. Their docs explicitly warn devs not to use npm install as this creates phantom dependencies.

Usually, when I need to upgrade a dependency within one of the projects, I use
rush add --package <package-name>@x.y.z --dev

It's not a widely used tool amongst front end ecosystem afaik, but I inherited this legacy setup and can't change it til I have time to migrate codebases 😓 But first, I have to upgrade Storybook to 7.0.

FAST.design's Storybook Setup

FAST Design has been using CSF2 in stories.

They use a series of helper functions and extended SB's type definitions to render and bind custom element templates within stories.

Example: button.stories.ts

Storybook Setup and ESM

Our project's Storybook setup currently closely follows FAST's setup, esp using @radium-v's helper functions for template rendering and binding to stories in CSF 2.

Re: CSF3 upgrade: I have been looking at how Nimble project sets up their storybook and writes custom functions to render FAST component templates in stories thanks to @rajsite

@usrrname
Copy link
Contributor Author

usrrname commented Apr 27, 2023

Reproductions galore: https://stackblitz.com/@usrrname/collections/fast-design-storybook-spikes

cc @shilman @yannbf Initial impressions after discussing with FAST maintainer @radium-v is that we both experience Vite to work well with minimal modifications and agonization, however I may have to rig up a webpack5 config for my work project as it's very entwined within the enterprise codebase.

Also, shout out to @rajsite and @yinon for their input on how they're using SB!

@divmgl
Copy link

divmgl commented May 3, 2023

Just went through the upgrade process for this using pnpm, which was very straightforward, but now I'm greeted with a similar error:

image

process is not defined

As a result we can't upgrade to the latest version of Storybook. We're also using a monorepo, however it's a Vite app.

@usrrname
Copy link
Contributor Author

usrrname commented May 3, 2023

@divmgl What command did you use to upgrade? you may find that you have to clear the sb cache for node_modules/storybook, remove your package-lock.json and also manually install the latest version of storybook and @storybook/cli as devdependency

@divmgl
Copy link

divmgl commented May 4, 2023

Just wanted to give a quick update that the reason this was happening was due to a bad Storybook configuration that I was using to patch up Vite 3 on Storybook 6.

const path = require("path")

module.exports = {
  stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
  addons: [
    "@storybook/addon-links",
    "@storybook/addon-essentials",
    "@storybook/addon-interactions",
  ],
  framework: "@storybook/react",
  core: {
    builder: "@storybook/builder-vite",
  },
  features: {
    storyStoreV7: true,
  },
  async viteFinal(config) {
    return {
      ...config,
      resolve: {
        alias: {
          "@permitflow/app": path.resolve(__dirname, "../src"),
          fixtures: path.resolve(__dirname, "../fixtures"),
        },
      },
    }
  },
}

Note the viteFinal. This is what was causing the error. So, in other words, disregard my comment and sorry about that! I upgraded Vite and Storybook and everything is now working as intended.

@shilman shilman assigned usrrname and unassigned shilman May 15, 2023
@usrrname
Copy link
Contributor Author

We've moved to a yarn2 workspace. gonna RESPIKE. LOL

@usrrname
Copy link
Contributor Author

Closing this issue as the integration issue no longer exists --the team migrated to a yarn 2/3 workspace

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

No branches or pull requests

3 participants