Failed to invoke SWC plugin in a Vite project
josemarcilio opened this issue · 7 comments
In my Vite project I have this following setup:
import react from "@vitejs/plugin-react-swc"
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react({ plugins: [["typewind/swc", {}]] })],
})
But when I run the project I got:
[vite] Internal server error: failed to handle: failed to invoke plugin: failed to invoke plugin on 'Some("project path/ClientApp/src/components/auth/auth-provider.tsx")'
Caused by:
0: failed to invoke `project path\ClientApp\node_modules\.pnpm\typewind@0.1.3_postcss@8.4.23_typescript@4.9.5\node_modules\typewind\dist\typewind_swc.wasm` as js transform plugin at project path\ClientApp\node_modules\.pnpm\typewind@0.1.3_postcss@8.4.23_typescript@4.9.5\node_modules\typewind\dist\typewind_swc.wasm
1: RuntimeError: unreachable
at rust_panic (<module>[310]:0x383c8)
at std::panicking::rust_panic_with_hook::hc5c73bd02fe928d4 (<module>[225]:0x2b611)
at std::panicking::begin_panic_handler::{{closure}}::hcd8b0196239bb506 (<module>[316]:0x38b25)
at std::sys_common::backtrace::__rust_end_short_backtrace::h634ecf1fa70ae144 (<module>[315]:0x38a5e)
at rust_begin_unwind (<module>[149]:0x2146c)
at core::panicking::panic_fmt::h1024bc10a158814e (<module>[82]:0xfb7f)
at core::result::unwrap_failed::h4f10a8b6d25baa65 (<module>[31]:0x4ff7)
at rkyv::impls::core::<impl rkyv::DeserializeUnsized<[U],D> for [T]>::deserialize_unsized::h23eb454e66ed7cc7 (<module>[586]:0x84604)
at swc_ecma_ast::decl::_::<impl rkyv::Deserialize<swc_ecma_ast::decl::Decl,__D> for <swc_ecma_ast::decl::Decl as rkyv::Archive>::Archived>::deserialize::hce2fff52aaeab3dd (<module>[618]:0x8ec3e)
at rkyv::impls::core::<impl rkyv::DeserializeUnsized<[U],D> for [T]>::deserialize_unsized::h5244dff0d14890db (<module>[105]:0x18175)
at __transform_plugin_process_impl (<module>[104]:0x14f34)
at __transform_plugin_process_impl.command_export (<module>[883]:0xced76)
Hey, I tried this but seems to work fine. Can you setup a reproduction?
I have the same problem!
Thanks for reporting. Can you please try setting up a reproduction for this? A minimal app where you see this error occurring so I can further look into it
Confirmed that this also happens on a vanilla Next.js project I spun up today, running Next.js v13.5.3
. Downgrading to Next.js 13.2.3
does fix it, but isn't viable long-term.
Reproduced via npx create-next-app@latest
and then following the instructions for installation on the Typewind website.
I wonder if this could be related to the version of @swc/core
? Like they found in https://github.com/lingui/swc-plugin#compatibility.
I have a build of Typewind working locally with updated Cargo dependencies for SWC:
diff --git a/packages/typewind/Cargo.toml b/packages/typewind/Cargo.toml
index f78a8a1..e478a2e 100644
--- a/packages/typewind/Cargo.toml
+++ b/packages/typewind/Cargo.toml
@@ -13,8 +13,8 @@ lto = true
[dependencies]
serde = "1"
serde_json = "1.0.93"
-swc_core = { version = "0.59.*", features = ["ecma_plugin_transform"] }
-swc_ecma_codegen = "0.129.13"
+swc_core = { version = "0.79.28", features = ["ecma_plugin_transform"] }
+swc_ecma_codegen = "0.145.5"
# .cargo/config defines few alias to build plugin.
# cargo build-wasi generates wasm-wasi32 binary
Then I ran
cargo update
npm run build
And then linked it into my Next 13.5.3 project, and it works again. I also built with Rust nightly-2023-03-20
because they also are doing that in the lingui project linked above.
I can PR this change or you can do it yourself @Mokshit06.
@mutewinter Thank you, this is great! I had a feeling this might be related to swc compat as well, but hadn't been getting the time to test it out. I'll do these changes and make a release :)
Should be fixed now!