reg-viz / storycap

A Storybook Addon, Save the screenshot image of your stories :camera: via puppeteer.
https://www.npmjs.com/package/storycap
MIT License
694 stars 89 forks source link

Limit to only using require to let Rollup bundler to detect the file as cjs file #857

Closed indigolain closed 3 months ago

indigolain commented 4 months ago

May fix https://github.com/reg-viz/storycap/issues/856 ? Having import statements in a file makes @rollup/plugin-commonjs to skip the conversion from CommonJS to ES Module. Changing the import statement to require should make @rollup/plugin-commonjs handle the file and successfully convert it.

en-rai commented 3 months ago

when will this pr be merged? waiting for this 👍

Quramy commented 3 months ago

@indigolain Sorry my late feedback.

I attempt to build Storybook at the v8-vite example but I got the following vite log.

=> Failed to build the preview
Error: [vite:load-fallback] Could not load ./node_modules/storycap/lib/client/with-screenshot (imported by .storybook/preview.js): ENOENT: no such file or directory, open './node_modules/storycap/lib/client/with-screenshot'

I think the log means the #856 issue is not solved.

indigolain commented 3 months ago

@Quramy Thank you for reviewing my PR! The error you are getting is because the vite project that I setup expects storycap to be installed and present under node_modules ( this is where the config is applied).

Without setting this resolve.alias, when you try to build the storybook, it will result in throwing the following error.

=> Failed to build the preview
Error: [commonjs--resolver] Failed to resolve entry for package "storycap". The package may have incorrect main/module/exports specified in its package.json.

It seems that the commonjs--resolver requires the storycap dependency to be inside package.json by default, unless you configure the resolver.

I've added a pre hooks to build-storybook for populating the storycap build with 5c26134749713445911a38a7f8aac5f817b5d805 to resolve the error you are getting, should this resolve the issue?

indigolain commented 3 months ago

Thank you!!