storybook: Storyshots: running `initStoryshots` fails with "require.requireActual is not a function"
If you are reporting a bug or requesting support, start here:
Bug or support request summary
Created a new project for the documentation software, and got an error when running the test (step 2).
Steps to reproduce
- https://www.learnstorybook.com/intro-to-storybook/svelte/en/get-started/
- https://www.learnstorybook.com/intro-to-storybook/svelte/en/simple-component/
Please specify which version of Storybook and optionally any affected addons that you’re running
//* package.json *//
{
"name": "svelte-app",
"version": "0.0.1",
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
"start": "sirv public",
"storybook": "start-storybook -p 6006 -s public",
"build-storybook": "build-storybook",
"test": "jest --watchAll"
},
"dependencies": {
"sirv-cli": "^0.4.4"
},
"devDependencies": {
"@babel/core": "^7.9.6",
"@rollup/plugin-commonjs": "^12.0.0",
"@rollup/plugin-node-resolve": "^8.0.0",
"@storybook/addon-actions": "^5.3.19",
"@storybook/addon-links": "^5.3.19",
"@storybook/addon-storyshots": "^5.3.19",
"@storybook/addons": "^5.3.19",
"@storybook/svelte": "^5.3.19",
"@testing-library/jest-dom": "^5.8.0",
"@testing-library/svelte": "^3.0.0",
"babel-loader": "^8.1.0",
"jest": "^26.0.1",
"jest-transform-svelte": "^2.1.1",
"rollup": "^2.3.4",
"rollup-plugin-livereload": "^1.0.0",
"rollup-plugin-svelte": "^5.0.3",
"rollup-plugin-terser": "^5.1.2",
"svelte": "^3.22.3",
"svelte-loader": "^2.13.6"
},
"jest": {
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.stories\\.[jt]sx?$": "<rootDir>node_modules/@storybook/addon-storyshots/injectFileName",
"^.+\\.svelte$": "jest-transform-svelte"
},
"setupFilesAfterEnv": [
"@testing-library/jest-dom/extend-expect"
]
}
}
Screenshots / Screencast / Code Snippets (Optional)
Test code:
import initStoryshots from '@storybook/addon-storyshots';
initStoryshots();
Error stack:
PASS tests/sample.test.js
FAIL tests/storybook.test.js
● Test suite failed to run
TypeError: require.requireActual is not a function
1 | import initStoryshots from '@storybook/addon-storyshots';
2 |
> 3 | initStoryshots();
| ^
at Object.load (node_modules/@storybook/addon-storyshots/dist/frameworks/svelte/loader.js:25:29)
at Object.loadFramework [as default] (node_modules/@storybook/addon-storyshots/dist/frameworks/frameworkLoader.js:26:19)
at testStorySnapshots (node_modules/@storybook/addon-storyshots/dist/api/index.js:48:39)
at Object.<anonymous> (tests/storybook.test.js:3:1)
Test Suites: 1 failed, 1 passed, 2 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 8.368 s
Ran all test suites.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 14
- Comments: 22 (12 by maintainers)
I’ve updated to 6 but still getting the error. Downgrade jest to "^25.1.0"only seems to work.
Error:
@pelotom that seems to be the case. I was checking it and the behaviour occurs. Bumping back to Jest 24 the addon will work properly. And when the 5.3.20 version of the addon goes live i’m going to bump to jest 26 take another look at it to see if the problem persists
I saw the theme #10455 and the closed #10631. But the problem is apparently not completely fixed. I am new to Storybook and find it difficult to fix the problem or offer a solution on my own. I also understand that we are actively working on a new version, but I hope that this error will be fixed in the current stable version in the near future, since it is probably not only related to Svelte.
Thank you for your attention to this issue.
I’m also experiencing this issue with React.
It’s not stale
Issue still happening. Got it today with jest v26.4.0.
May be this would help https://github.com/storybookjs/storybook/issues/10351#issuecomment-644667392
We’ve ugpraded to Jest 26 in 6.0, but due to time constraints I don’t think we can back-port that to 5.3. I tried it quickly, ran into problems, and aborted to focus on getting 6 shipped. I’d advise anybody who runs into this to upgrade to 6
Downgrading to Jest 24.0.1 fixed the issue for me.