vitejs / vite-plugin-react-swc

Speed up your Vite dev server with SWC
MIT License
774 stars 49 forks source link

Failed to invoke as js transfrom plugin #192

Closed d4mr closed 5 months ago

d4mr commented 5 months ago

Using @swc/core version 1.3.107, I get this error when I try to use @swc-jotai/react-refresh.

failed to handle: failed to invoke plugin: failed to invoke plugin on 'Some("[...]/src/main.tsx")'

Caused by:
    0: failed to invoke `[...]/node_modules/.pnpm/@swc-jotai+react-refresh@0.1.0/node_modules/@swc-jotai/react-refresh/swc_jotai_react_refresh.wasm` as js transform plugin at [...]/node_modules/.pnpm/@swc-jotai+react-refresh@0.1.0/node_modules/@swc-jotai/react-refresh/swc_jotai_react_refresh.wasm
    1: RuntimeError: unreachable
[...]/src/main.tsx

Downgrading @swc/core to version 1.3.101, I no longer get this error, and everything seems to work. I am unsure whether I should file an issue there or here, please let me know if I should create one there instead.

ArnaudBarre commented 5 months ago

Yes this is clearly an issue with SWC, maybe an incompatibility between the plugin version and the core version

stevebeauge commented 4 months ago

I'm facing the same issue. However, I'm not sure to get how to handle this. I forced @swc/core in my project's package.json to ~1.3.107, and "deduped" my dep tree (using pnpm dedupe).

I still get the same error as @d4mr reported, on my dev computer. On stackblitz (https://stackblitz.com/edit/vitejs-vite-sqthkz?file=package.json,vite.config.ts,src%2Fmain.tsx,src%2FApp.tsx&terminal=dev) , it's working even with the latest versions, but the plugin does not seems to be run at all.

Is there any working sample somewhere, combining vite-plugin-react-swc and jotai plugin ?

stevebeauge commented 4 months ago

Found a workaround here: https://github.com/pmndrs/swc-jotai/issues/23#issuecomment-1944195939

I added in my package.json file:

{
     "pnpm": {
        "overrides": {
            "@swc/core": "1.3.105"
        }
    }
}

This way, it forces vite-plugin-react-swc to downgrade its swc dependency.