lingui / swc-plugin

A SWC Plugin For LinguiJS
https://www.npmjs.com/package/@lingui/swc-plugin
MIT License
64 stars 13 forks source link

Fatal Error with @swc/core > 1.3.105 #78

Closed webartoli closed 9 months ago

webartoli commented 9 months ago

Last version of @swc/core that works with this plugin is 1.3.105.

Upgrading to @swc/core:1.4 or @swc/core:1.3.x fill fail. OS Windows.

Caused by:
    0: failed to invoke `C:\workspace\node_modules\@lingui\swc-plugin\target\wasm32-wasi\release\lingui_macro_plugin.wasm` as js transform plugin at 
C:\workspace\node_modules\@lingui\swc-plugin\target\wasm32-wasi\release\lingui_macro_plugin.wasm
    1: RuntimeError: unreachable
           at __rust_start_panic (<module>[2736]:0x11be35)
           at rust_panic (<module>[2728]:0x11bb9e)
           at std::panicking::rust_panic_with_hook::hccaf2b7e6df76f84 (<module>[2727]:0x11bb65)
           at std::panicking::begin_panic_handler::{{closure}}::hf6623888c16dc6bb (<module>[2715]:0x11ac13)
           at std::sys_common::backtrace::__rust_end_short_backtrace::h585f9f94f404c402 (<module>[2714]:0x11ab3d)
           at rust_begin_unwind (<module>[2722]:0x11b1d1)
           at core::panicking::panic_fmt::h1e0ee2f017a8252e (<module>[2867]:0x129b29)
           at core::result::unwrap_failed::h10ae8691526cb788 (<module>[2904]:0x12ff7a)
           at rkyv::impls::alloc::vec::<impl rkyv::Deserialize<alloc::vec::Vec<T>,D> for rkyv::vec::ArchivedVec<<T as rkyv::Archive>::Archived>>::deserialize::ha7c5bcea2c12eee9 (<module>[412]:0x60f48)
           at rkyv::impls::core::<impl rkyv::DeserializeUnsized<T,D> for <T as rkyv::Archive>::Archived>::deserialize_unsized::hc9024ee97bd35ba4 (<module>[76]:0x12565)
           at swc_ecma_ast::expr::_::<impl rkyv::Deserialize<swc_ecma_ast::expr::MemberExpr,__D> for <swc_ecma_ast::expr::MemberExpr as rkyv::Archive>::Archived>::deserialize::h1ad15d83dd09b194 (<module>[105]:0x284df)
           at rkyv::impls::core::<impl rkyv::DeserializeUnsized<T,D> for <T as rkyv::Archive>::Archived>::deserialize_unsized::hc9024ee97bd35ba4 (<module>[76]:0x138a7)
           at rkyv::impls::core::<impl rkyv::DeserializeUnsized<T,D> for <T as rkyv::Archive>::Archived>::deserialize_unsized::hc9024ee97bd35ba4 (<module>[76]:0x124fd)
           at swc_ecma_ast::stmt::_::<impl rkyv::Deserialize<swc_ecma_ast::stmt::Stmt,__D> for <swc_ecma_ast::stmt::Stmt as rkyv::Archive>::Archived>::deserialize::hf29be54d952adb60 (<module>[110]:0x29fb2)
           at rkyv::impls::alloc::vec::<impl rkyv::Deserialize<alloc::vec::Vec<T>,D> for rkyv::vec::ArchivedVec<<T as rkyv::Archive>::Archived>>::deserialize::h54a0a2a0cf609a47 (<module>[20]:0x322e)
           at swc_common::plugin::serialized::_::<impl rkyv::Deserialize<swc_common::plugin::serialized::VersionedSerializable<T>,__D> for <swc_common::plugin::serialized::VersionedSerializable<T> as rkyv::Archive>::Archived>::deserialize::h4f433e64d5224fb8 (<module>[19]:0x2842)
           at __transform_plugin_process_impl (<module>[473]:0x6b175)
           at __transform_plugin_process_impl.command_export (<module>[3025]:0x137278)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
{
  // package.json
  "dependencies": {
    "@lingui/detect-locale": "^4.7.0",
    "@lingui/react": "^4.7.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-router-dom": "^6.22.0"
  },
  "devDependencies": {
    "@lingui/cli": "^4.7.0",
    "@lingui/macro": "^4.7.0",
    "@lingui/swc-plugin": "^4.0.4",
    "@lingui/vite-plugin": "^4.7.0",
    "@types/react": "^18.2.53",
    "@types/react-dom": "^18.2.18",
    "@typescript-eslint/eslint-plugin": "^6.20.0",
    "@typescript-eslint/parser": "^6.20.0",
    "@vitejs/plugin-react-swc": "^3.6.0",
    "typescript": "^5.3.3",
    "vite": "^5.0.12",
    "vite-plugin-svgr": "^4.2.0",
    "vite-tsconfig-paths": "^4.3.1",
    "vitest": "^1.2.2"
  },
  "overrides": {
    "vite": "$vite"
  }
}

as a workaround @swc/core version must be fixed as follows:

{
  // package.json
  "overrides": {
    "@swc/core": "1.3.105"
  }
}
webartoli commented 9 months ago
With `RUST_BACKTRACE=1` ``` Caused by: 0: failed to invoke `C:\workspace\node_modules\@lingui\swc-plugin\target\wasm32-wasi\release\lingui_macro_plugin.wasm` as js transform plugin at C:\workspace\node_modules\@lingui\swc-plugin\target\wasm32-wasi\release\lingui_macro_plugin.wasm 1: RuntimeError: unreachable at __rust_start_panic ([2736]:0x11be35) at rust_panic ([2728]:0x11bb9e) at std::panicking::rust_panic_with_hook::hccaf2b7e6df76f84 ([2727]:0x11bb65) at std::panicking::begin_panic_handler::{{closure}}::hf6623888c16dc6bb ([2715]:0x11ac13) at std::sys_common::backtrace::__rust_end_short_backtrace::h585f9f94f404c402 ([2714]:0x11ab3d) at rust_begin_unwind ([2722]:0x11b1d1) at core::panicking::panic_fmt::h1e0ee2f017a8252e ([2867]:0x129b29) at core::result::unwrap_failed::h10ae8691526cb788 ([2904]:0x12ff7a) at rkyv::impls::alloc::vec::,D> for rkyv::vec::ArchivedVec<::Archived>>::deserialize::ha7c5bcea2c12eee9 ([412]:0x60f48) at rkyv::impls::core:: for ::Archived>::deserialize_unsized::hc9024ee97bd35ba4 ([76]:0x12565) at swc_ecma_ast::expr::_:: for ::Archived>::deserialize::h1ad15d83dd09b194 ([105]:0x284df) at rkyv::impls::core:: for ::Archived>::deserialize_unsized::hc9024ee97bd35ba4 ([76]:0x138a7) at rkyv::impls::core:: for ::Archived>::deserialize_unsized::hc9024ee97bd35ba4 ([76]:0x124fd) at swc_ecma_ast::stmt::_:: for ::Archived>::deserialize::hf29be54d952adb60 ([110]:0x29fb2) at rkyv::impls::alloc::vec::,D> for rkyv::vec::ArchivedVec<::Archived>>::deserialize::h54a0a2a0cf609a47 ([20]:0x322e) at swc_common::plugin::serialized::_::,__D> for as rkyv::Archive>::Archived>::deserialize::h4f433e64d5224fb8 ([19]:0x2842) at __transform_plugin_process_impl ([473]:0x6b175) at __transform_plugin_process_impl.command_export ([3025]:0x137278) Stack backtrace: 0: napi_register_module_v1 1: napi_register_module_v1 2: napi_register_module_v1 3: napi_register_module_v1 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: v8::base::RandomNumberGenerator::max 22: uv_queue_work 23: uv_poll_stop 24: inflateValidate 25: BaseThreadInitThunk 26: RtlUserThreadStart Stack backtrace: 0: napi_register_module_v1 1: napi_register_module_v1 2: napi_register_module_v1 3: 4: 5: 6: 7: 8: v8::base::RandomNumberGenerator::max 9: uv_queue_work 10: uv_poll_stop 11: inflateValidate 12: BaseThreadInitThunk 13: RtlUserThreadStart ```
timofei-iatsenko commented 9 months ago

it's incompatible, they changed AST

https://swc.rs/docs/plugin/selecting-swc-core Latest version of plugin is built with swc_core@0.79.x

webartoli commented 9 months ago

I see. I propose to specify @swc/core as a dependency with supported version instead of optional peer deps.

timofei-iatsenko commented 9 months ago

It's not an option. SWC plugins still experimental, they do not provide semver compatibility for them. There is no way to provide a correct compatibility range, because it is not available ahead of time. In other words, when i built a latest version of the plugin it supported the newest version of swc, and it is not knowable from what version it will stop work until they release this version.

Also nextjs uses SWC under the hood, but not have it in theirs package.json, because they have their own flavor (they build it from rust sources together with some proprietary extensions), so nextjs users will not be happy to have useless swc dependency.

timofei-iatsenko commented 9 months ago

https://github.com/lingui/swc-plugin/releases/tag/4.0.5 built with swc_core@0.87.28 should support @swc/core@1.3.81 ~ @swc/core@1.3.105

Note: this is still not the latest swc_core available, since this plugin is aligned NextJS releases rather than @swc/core