Skip to content
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

Error with storybook #40

Open
stouch opened this issue Jul 31, 2023 · 3 comments
Open

Error with storybook #40

stouch opened this issue Jul 31, 2023 · 3 comments

Comments

@stouch
Copy link

stouch commented Jul 31, 2023

We met difficulties to setup a Storybook on a Vite project that use stailwc. (https://storybook.js.org/docs/react/configure/frameworks#configure)

We can successfuly make tw working in our exported components in our dist directory (that we include in another project, so rollup works well).

But we got the following error when we are running RUST_BACKTRACE=full npm run storybook :

8:27:11 PM [vite] Internal server error: failed to handle: failed to invoke plugin: failed to invoke plugin on 'Some("/var/webprojects/our-uikit/.storybook/stories/TextField.stories.ts")'

Caused by:
    0: failed to invoke `/var/webprojects/our-uikit/node_modules/@swc/plugin-styled-components/swc_plugin_styled_components.wasm` as js transform plugin at /var/webprojects/our-uikit/node_modules/@swc/plugin-styled-components/swc_plugin_styled_components.wasm
    1: RuntimeError: call stack exhausted
  Plugin: vite:react-swc
  File: /var/webprojects/our-uikit/.storybook/stories/TextField.stories.ts

Is there any good practice to setup storybook using your lib ?

Here is our vite.config.ts :

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import dts from "vite-plugin-dts";
import stailwc from "stailwc/install";
import path from "path";

export default defineConfig({
  plugins: [
    dts(),
    react({
      plugins: [
        stailwc({
          engine: "styled-components",
          tailwindPath: path.join(__dirname, "tailwind.config.cjs"),
        }),
        ["@swc/plugin-styled-components", {}],
      ],
    }),
  ],

And here is our .storybook/main.tsx :

import type { StorybookConfig } from "@storybook/react-vite";

const config: StorybookConfig = {
  stories: ["./stories/*.mdx", "./stories/*.stories.@(js|jsx|ts|tsx)"],
  addons: [
    "@storybook/addon-links",
    "@storybook/addon-essentials",
    "@storybook/addon-interactions",
    'storybook-addon-swc',
  ],
  framework: {
    name: "@storybook/react-vite",
    options: {},
  },
  docs: {
    autodocs: "tag",
  },
};
export default config;

Thanks a lot

@stouch
Copy link
Author

stouch commented Aug 1, 2023

In our specific config (vite + swc, see above), stailwc needs @swc/plugins-styled-components (instead of @swc/plugin-emotion in repo example) which is runtime-built with a specific version of swc_core depending on version... AND, in the meantime, last version of stailwc is built in runtime using swc_core@0.76.X crates.io version (looking at its Cargo.toml) so this seems that this led to a conflict.
To make stailwc work, we needed to keep @swc/core and @swc/plugin-styled-components fitting with swc_core crates.io version 0.76.X (https://swc.rs/docs/plugin/selecting-swc-core#v076x) which led us to use :

    "@swc/core": "^1.3.62",
    "@swc/plugin-styled-components": "^1.5.67",

This fixed our issue but it would be great to specify @swc/xxx versions in Vite examples of this repo. @arlyon

@stouch stouch closed this as completed Aug 1, 2023
@stouch
Copy link
Author

stouch commented Aug 2, 2023

For the record, just by updating npm i @swc/plugin-styled-components from 1.5.67 to 1.5.68, my storybook is broken : so it seems to problems start with this commit swc-project/plugins@05d992e in plugin-styled-components repo.

Screenshot from 2023-08-02 10-28-15

Careful use swc/plugin-styled-components version!

@stouch stouch reopened this Aug 2, 2023
@arlyon
Copy link
Owner

arlyon commented Aug 19, 2023

For some context on why this error may happen, stailwc is unfortunately quite tightly coupled to the version of SWC being used to run it, as SWC is currently a very turbulent (pre-1.0) codebase. This types of errors will happen frequently, so my recommendation is to make sure to pin your versions. If you have known-working versions to report, I will add them to the compatibility chart on the readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants