addon-interactions: jest-mock global is not defined
See original GitHub issueMy storybook setup works great until i add Interactions (with @storybook/jest):
Browser console fatal error (nothing loads):
Uncaught SyntaxError: The requested module '/node_modules/jest-mock/build/index.js?v=de720b8b' does not provide an export named 'fn'
However, adding /register
seemed to work (based on https://stackoverflow.com/questions/68360359/storybook-addon-value-should-end-in-register-or-it-should-be-a-valid-preset):
"addons": [
"@storybook/addon-links",
"@storybook/addon-essentials",
'@storybook/addon-interactions/register'
],
BUT trying to actually use @storybook/jest in a story doesn’t work:
import { expect } from '@storybook/jest';
Gives you this error in the browser:
Uncaught ReferenceError: global is not defined at node_modules/jest-mock/build/index.js
Commenting out this in main works with a normal Interactions install:
"core": {
"builder": "storybook-builder-vite"
},
TL;DR: So default webpack works for Interactions; Vite builder doesn’t. (Other add-ons seem to work fine with vite builder btw)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:6 (4 by maintainers)
@peteromano here the guide:
How to enable Storybook Interactions addon with Vite builder
.storybook/main.js
.storybook/preview.js
.storybook/preview-head.html
@IanVS unfortunately the Storybook Interactions addon is sometimes checks for arguments of a story on the Docs page and failed with warning:
Source of the error in the
@storybook/theming
package.I think it’s because the core Storybook addons it’s written in React and the
@storybook/addon-interactions
using Jest inside to do testing.New storybook projects created with
npx sb init
will automatically add apreview-head.html
to avoid this issue. There’s not much else that can be done until jest@28 is used by storybook.