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]: 7.0.0 - Module '"@storybook/addon-actions/decorator"' has no exported member 'withActions' #21887

Closed
jattasNI opened this issue Apr 3, 2023 · 5 comments · Fixed by #21922 or ni/nimble#1147

Comments

@jattasNI
Copy link

jattasNI commented Apr 3, 2023

Describe the bug

According to the 7.0 migration guide I should be able to use the withActions decorator via import { withActions } from '@storybook/addon-actions/decorator';. But when I run TypeScript compile this gives me "error TS2305: Module '"@storybook/addon-actions/decorator"' has no exported member 'withActions'."

It looks like withActions is exported from addons/actions/src/decorator.ts but is not exported from addons/actions/src/index.ts. This differs from other decorators like withLinks which are exported from their index.ts.

It looks like this is intended to work via the "exports" field in package.json for declaring multiple entry points in package.json. That feature gained support in TypeScript 4.7.0. But I tried upgrading my project from TypeScript 4.6.4 to 4.7.0 and still saw the same error.

To Reproduce

This is reproducing in this branch of the ni/nimble repository. To reproduce, clone that repo, checkout that branch, run npm i and npm run build. If a more targeted reproduction would be helpful I can try to create one.

System

Environment Info:

  System:
    OS: macOS 13.2.1
    CPU: (10) arm64 Apple M1 Max
  Binaries:
    Node: 16.15.1 - /usr/local/bin/node
    npm: 8.11.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 111.0.5563.146
    Firefox: 111.0.1
    Safari: 16.3

Additional context

This was also reported in #21308 but that bug is marked as fixed and I'm still seeing the problem. I don't have permission to re-open that issue and I was worried my comment there would get lost so I filed a new one; sorry if that's not the correct workflow!

@shilman
Copy link
Member

shilman commented Apr 4, 2023

@jattasNI thanks for re-filing the issue and for the detailed backstory. we'll see if we can get to the bottom of it. in the meantime can you declare the module as a workaround?

declare module '@storybook/addon-actions/decorator';

@shilman shilman added the html label Apr 4, 2023
@shilman
Copy link
Member

shilman commented Apr 4, 2023

@ndelangen we have stories for this in https://github.com/storybookjs/storybook/blob/next/code/addons/actions/template/stories/parameters.stories.ts, but they are also producing a TS error in VScode. Mind taking a look?

@shilman shilman assigned ndelangen and kasperpeulen and unassigned ndelangen Apr 4, 2023
@shilman shilman moved this to Blocking stabilization in Core Team Projects Apr 4, 2023
@jattasNI
Copy link
Author

jattasNI commented Apr 4, 2023

@shilman thanks for the workaround, it does work for us!

In case it helps others, the full picture that worked with our TypeScript configuration was to add a new declaration file containing the workaround, storybook-declarations.d.ts:

declare module '@storybook/addon-actions/decorator';

And then import and use withActions as described in the docs:

import { withActions } from '@storybook/addon-actions/decorator';
...
{
    decorators: [withActions],
}

Once this issue is addressed hopefully we can just delete the new declaration file.

ndelangen added a commit that referenced this issue Apr 4, 2023
@ndelangen ndelangen assigned ndelangen and unassigned kasperpeulen Apr 4, 2023
jattasNI added a commit to ni/nimble that referenced this issue Apr 4, 2023
# Pull Request

## 🤨 Rationale

After #1134, the Actions tab in Storybook was no longer displaying
events fired by components. This is one of the issues tracked in #1146.

As described in the [Storybook 7 migration
guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#removed-auto-injection-of-storybookaddon-actions-decorator),
the actions addon is no longer enabled by default and it must be enabled
by configuring the story with `decorators: [withActions]`. However, the
`withActions` decorator wasn't exported from Storybook in a way that we
could import it (see
storybookjs/storybook#21887). A Storybook dev
commented on that issue with a workaround that we can use until they fix
that bug.

## 👩‍💻 Implementation

1. Add a [TypeScript shorthand ambient module
declaration](https://www.typescriptlang.org/docs/handbook/modules.html#shorthand-ambient-modules)
for the import URL that contains `withActions`. See
`/utilities/tests/storybook-declarations.d.ts`.
2. Update all stories that expose an action to import `withActions` and
configure it as a decorator (also reordered a few imports to group them
by package)

## 🧪 Testing

Manually verified many of the stories that have actions are now firing
them.

## ✅ Checklist

- [x] I have updated the project documentation to reflect my changes or
determined no changes are needed.
@github-project-automation github-project-automation bot moved this from Blocking stabilization to Done in Core Team Projects Apr 5, 2023
@shilman
Copy link
Member

shilman commented Apr 5, 2023

Good golly!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.1.0-alpha.0 containing PR #21922 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb@next upgrade --prerelease

@shilman
Copy link
Member

shilman commented Apr 12, 2023

Huzzah!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.3 containing PR #21922 that references this issue. Upgrade today to the @latest NPM tag to try it out!

npx sb@latest upgrade

rajsite pushed a commit to ni/nimble that referenced this issue Apr 12, 2023
# Pull Request

## 🤨 Rationale

Right after I submitted the upgrade to a release candidate of Storybook
7 in #1134, I noticed they [released the official
7.0.0](https://github.com/storybookjs/storybook/releases). Adopting the
latest patch addresses some of the issues in #1146.

## 👩‍💻 Implementation

1. Update to latest non-RC build in package.json and regenerate
package-lock.json
2. Regenerate one patch file since the file it was patching has a new
name
3. Add another patch file since they introduced another instance of
storybookjs/storybook#21820
4. Move off deprecated API for specifying `sourceTransform` as described
in [migration
guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#source-block)
5. Delete `storybook-declarations.ts` since this bug was closed
storybookjs/storybook#21887

## 🧪 Testing

Explored Storybook.

## ✅ Checklist

- [x] I have updated the project documentation to reflect my changes or
determined no changes are needed.
JonasKellerer added a commit to GenSpectrum/dashboard-components that referenced this issue Feb 22, 2024
JonasKellerer added a commit to GenSpectrum/dashboard-components that referenced this issue Feb 22, 2024
JonasKellerer added a commit to GenSpectrum/dashboard-components that referenced this issue Feb 22, 2024
JonasKellerer added a commit to GenSpectrum/dashboard-components that referenced this issue Feb 23, 2024
JonasKellerer added a commit to GenSpectrum/dashboard-components that referenced this issue Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
4 participants