chromaui / storybook-addon-pseudo-states

CSS pseudo-classes for Storybook
MIT License
88 stars 28 forks source link

Optional chaining error in 1.15.2 #48

Closed samturrell closed 1 year ago

samturrell commented 1 year ago

Hi!

There seems to be a bug introduced in 1.15.2 where optional chaining has been used. This creates the following error:

ERROR in ./node_modules/storybook-addon-pseudo-states/dist/esm/withPseudoState.js 91:17
Module parse failed: Unexpected token (91:17)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| const rewriteStyleSheets = shadowRoot => {
|   let styleSheets = shadowRoot ? shadowRoot.styleSheets : document.styleSheets;
>   if (shadowRoot?.adoptedStyleSheets?.length) styleSheets = shadowRoot.adoptedStyleSheets;
|   Array.from(styleSheets).forEach(sheet => rewriteStyleSheet(sheet, shadowRoot, shadowHosts));
| };

Node version: v14.19.3 Plugin version: 1.15.2 Webpack version: 4.46.0 Storybook version: 6.5.14

Would it be possible to compile the optional chaining via babel in the generated module code?

sag1v commented 1 year ago

Can confirm with latest version and storybook 6.5.13

steffex commented 1 year ago

Can also confirm with latest version and storybook 6.5.15

Andjag commented 1 year ago

Getting same error as well after upgrading from 1.15.1 => 1.15.2 and having storybook 6.5.6

filipw01 commented 1 year ago

Just to give more context, this happens because webpack 4 doesn't support optional chaining. The workaround is to use webpack 5 or vite builder or upgrade to storybook 7 (currently in beta)

CHE1RON commented 1 year ago

For everyone using vite-builder encountering this problem, make sure to follow the migration steps described here 😉

riotrah commented 1 year ago

Can we remove the optional chain call for those who want the fix from 1.15.2, but cannot upgrade webpack?

github-actions[bot] commented 1 year ago

:rocket: Issue was released in v2.0.0-next.2 :rocket: