-
Notifications
You must be signed in to change notification settings - Fork 89
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
non-legacy withScreenshot
decorator stopped working after 4.3.0
#856
Comments
I think this issue is due to not considering bundling these require expressions procedure by Rollup . @indigolain Do you have any idea to solve this? 📝I got the following js, which is built by try {
a = require("@storybook/addons").makeDecorator;
} catch {}
try {
a = require("@storybook/preview-api").makeDecorator; // Not resolved
} catch {} And let makeDecorator;
try {
makeDecorator = Object(
(function webpackMissingModule() {
var e = new Error("Cannot find module '@storybook/addons'");
throw ((e.code = "MODULE_NOT_FOUND"), e);
})()
);
} catch {}
try {
makeDecorator = __webpack_require__(
"@storybook/preview-api"
).makeDecorator;
} catch {} |
Thank you for reporting the issue! Also, if this doesn't work, are there any branches or repos I could debug around 🙏 ? |
@indigolain |
Ah, I see, you mean how to debug storycap build itself. Please disregard my above comment 🙏 |
@ysgk |
Thanks to address it so quickly. I updated the previous mentioned project to Storybook 8.0.4 and Storycap 4.3.1 but errors still persist. When running the development server everything runs smoothly but when Storybook is built in statics at it runs on a HTTP server the error persist, now console reports the following:
and
AFAIK ESM modules should import things using Maybe this MR makes sense, to avoid conditional imports on the I've moved the decorator instantiation to my project and it works as expected: import { makeDecorator } from "@storybook/preview-api";
import { triggerScreenshot } from "../node_modules/storycap/lib-esm/client/trigger-screenshot";
export const withScreenshot = makeDecorator({
name: "withScreenshot",
parameterName: "screenshot",
skipIfNoParametersOrOptions: false,
wrapper: (getStory, context, { parameters, options }) => {
if (
typeof process !== "undefined" &&
process?.env.JEST_WORKER_ID !== undefined
) {
return getStory(context);
}
const screenshotOptions = parameters || options;
triggerScreenshot(screenshotOptions, context);
return getStory(context);
},
}); |
Same problem with the recent version here |
I mentioned the differential require expressions issue to #860. And I've changed to remove I published the above version as |
I was facing the same situation with @alejandrofdiaz. In my case, 5.0.0-alpha.0 worked with storybook@7.6.17 👍 |
I confirm that Storycap 5 works with Storybook 8 and Vite + React config. |
Problem
When building (not reproduced on development server) Storybook with the configuration below,
withScreenshot
decorator isn't defined becausemakeDecorator
is always undefined, it causes the following line setswithScreenshotDecorator
as undefined, which causes on this line to export the legacy decorator instead.As you can see in the below configuration this project does not have
@storybook/addons
or@storybook/preview-api
defined in thepackage.json
, but usingnpm why @storybook/preview-api
I see it is used by another dependency. In any case, I've already tested defining@storybook/preview-api
(and also@storybook/addons
) in thepackage.json
and it didn't solve the problem.I've solved the problem using the legacy
withScreenshot
decorator, but I think it is a bug that should be fixed. I've also checked that none of the previously defined decorators are causing the problem, removing all of the decorators and leaving onlywithScreenshot
decorator, the problem persists.Click here to see the `npm why @storybook/preview-api` log
storycap
probably requires@storybook/preview-api
as a peerDependency maybe?Reproduced with
"storycap": "4.3.0
"storybook": "8.0.1",
"@storybook/addon-essentials": "8.0.1",
"@storybook/react": "8.0.1",
"@storybook/react-vite": "8.0.1",
"@storybook/addon-essentials" is not referenced in dependencies but it is a dependency of "storybook".
Vite configuration:
storycap
addon is added.non-legacy
withScreenshot
decorator is used inpreview.tsx
file:Related
The text was updated successfully, but these errors were encountered: