addon-designs: Dependency on @storybook/api or incompatibility with latest alpha of storybook

Affected design types

  • figma
  • figspec
  • link
  • image
  • iframe

Describe the bug

I updated Storybook from alpha.49 to alpha.54 (next as of today) and storybook-addon-designs from beta.1 to beta.2 and I got the following error:

✘ [ERROR] Could not resolve "@storybook/api"

    node_modules/storybook-addon-designs/esm/register/index.js:2:29:
      2 │ import { useParameter } from "@storybook/api";
        ╵                              ~~~~~~~~~~~~~~~~

  You can mark the path "@storybook/api" as external to exclude it from the bundle, which will
  remove this error.

✘ [ERROR] Could not resolve "@storybook/api"

    node_modules/storybook-addon-designs/esm/register/containers/Wrapper.js:3:48:
      3 │ import { useParameter, useStorybookState } from "@storybook/api";
        ╵                                                 ~~~~~~~~~~~~~~~~

  You can mark the path "@storybook/api" as external to exclude it from the bundle, which will
  remove this error.

Installing @storybook/api in project as project’s own devDependency resolves the problem

How to reproduce the bug?

  1. Install storybook 7.0.0-alpha.49 and storybook-addon-designs 7.0.0-beta.1, check that storybook starts without errors
  2. update storybook to alpha.54 and storybook-addon-designs to beta-2, check that there are errors during start of storybook (storybook dev)

Expected behaviour

There’s no need to install @storybook/api in project to make storybook-addon-designs not break storybook dev

After quick bisect it turned out that alpha.54 stopped installing @storybook/api as its dependency

https://github.com/storybookjs/storybook/blob/next/CHANGELOG.md#700-alpha54-november-25-2022

Environment

  • Chrome / Chromium / Chromium based browsers
  • Firefox
  • macOS Safari
  • iOS Safari
  • Samsung Internet
  • Other

Affected versions

7.0.0-beta.2

Storybook versions

7.0.0-alpha.54

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 15

Most upvoted comments

I’m one of the Storybook maintainers. I focus primarily on documentation and community outreach. Just wanted to follow up on this issue, letting you know that the Storybook API for building addons is currently being updated to factor in the changes introduced by the upcoming 7.0 release. If you’re interested in making the required changes to help the community from benefiting from using your addon, we’ve prepared an abridged guide for the required changes here, and if you have any questions or issues, please reach out to us in the #prerelease channel in our Discord Server.

Hope you have a great day!

Stay safe

At the time I wrote https://github.com/pocka/storybook-addon-designs/issues/178#issuecomment-1365765087 and so far in my setup it looks like that:

  • I have msw-storybook-addon@1.6.3 which requires @storybook/addons
  • storybook-addon-designs@7.0.0-beta.2 has peerDependency of "@storybook/addons": "^6.4.0 || ^7.0.0"
  • back then I resolved the problem by adding @storybook/addons as devDependency of my project

and it worked.

Now I removed explicit dependency on @storybook/addons. Npm moved @storybook/addons to node_modules/msw-storybook-addon/node_modules/@storybook/addons and error came back

Then I removed and added back msw-storybook-addon which fixed the structure of my node_modules - now @storybook/addons is at node_modules/@storybook/addons and it works once again, yet now I have @storybook/addons@6.5.15 because msw-storybook-addon wants ^6.0.0.

I suppose it now works purely be accident - because I use msw-storybook-addon and it’s that one which allows storybook-addon-designs@7.0.0-beta.2 to work without problem.

I hope to have some more time to try beta.25 later - maybe something that comes with it (or with @storybook-addon-essentials which it’s probably save to assume vast majority uses) brings back @storybook/addons

By the end of the week I will check what I have now (last time I updated it was beta.19) and confirm if that problem still exists. And if it does I’ll try bumping to beta.25

I failed to reproduce the Could not resolve "@storybook/addons" problem, it could have been fixed or is caused by Storybook’s internal dependecy gotchas.

  1. mkdir sb-test
  2. Create a simple package.json
  3. npx -p storybook@next storybook init
  4. Remove @storybook/testing-library from package.json, as it pulls v6 deps
  5. Remove stories/Page.stories.js, as it uses @storybook/testing-library
  6. npm i -D --force storybook-addon-designs@beta (--force or --legacy-peer-deps is required as our package.json does not list SB@7beta in peer deps)
  7. Add a design parameter to the auto generated story
  8. npm run storybook
  9. The addon working as intended
% npm why @storybook/addons
@storybook/addons@7.0.0-beta.25 dev
node_modules/@storybook/addons
  @storybook/addons@"7.0.0-beta.25" from @storybook/builder-webpack5@7.0.0-beta.25
  node_modules/@storybook/builder-webpack5
    @storybook/builder-webpack5@"7.0.0-beta.25" from @storybook/react-webpack5@7.0.0-beta.25
    node_modules/@storybook/react-webpack5
      dev @storybook/react-webpack5@"^7.0.0-beta.25" from the root project

% cat package.json 
{
  "name": "sb-test",
  "version": "1.0.0",
  "scripts": {
    "storybook": "storybook dev -p 6006",
    "build-storybook": "storybook build"
  },
  "license": "UNLICENSED",
  "private": true,
  "devDependencies": {
    "@storybook/addon-essentials": "^7.0.0-beta.25",
    "@storybook/addon-interactions": "^7.0.0-beta.25",
    "@storybook/addon-links": "^7.0.0-beta.25",
    "@storybook/blocks": "^7.0.0-beta.25",
    "@storybook/react": "^7.0.0-beta.25",
    "@storybook/react-webpack5": "^7.0.0-beta.25",
    "prop-types": "^15.8.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "storybook": "^7.0.0-beta.25",
    "storybook-addon-designs": "^7.0.0-beta.2"
  }
}

@jrencz Would you mind sharing which Storybook packages and package manager you’re using?

@jonniebigodes Thank you for reaching out. I believe this addon is already compatible with Storybook v7 API-wise, thanks to these contributions.

Maybe you might escalate that to sb team. It’s still an alpha so maybe it wasn’t intended an/or can be reconsidered?

Oh… that’s an uncomfortable breaking change…

I believe there is no way to avoid manually installing @storybook/api:

  • Changing to @storybook/manager-api breaks v6.x compatibility
  • Moving @storybook/api into regular dependency would very likely cause a version mismatch problem

I’ll update README once Storybook v7.0-beta is shipped.