plugins icon indicating copy to clipboard operation
plugins copied to clipboard

Cannot use SWC plugins in Webpack loader

Open aegooby opened this issue 3 years ago • 6 comments

When using swc-loader in Webpack with the following .swcrc,

{
    "sync": true,
    "jsc": {
        "parser": {
            "syntax": "typescript",
            "tsx": true,
            "decorators": true,
            "dynamicImport": true
        },
        "transform": {
            "decoratorMetadata": true,
            "react": {
                "runtime": "automatic",
                "pragma": "React.createElement",
                "pragmaFrag": "React.Fragment",
                "throwIfNamespace": true,
                "useBuiltins": false,
                "refresh": true
            }
        },
        "experimental": {
            "plugins": [
                ["@swc/plugin-jest", {}]
            ]
        }
    }
}

I get the following error:

thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: LayoutError', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/rkyv-0.7.37/src/impls/core/mod.rs:265:67
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread '<unnamed>' panicked at 'failed to invoke plugin: failed to invoke `@swc/plugin-jest` as js transform plugin at ../node_modules/@swc/plugin-jest/swc_plugin_jest.wasm

Caused by:
    0: RuntimeError: call stack exhausted
    1: stk_ovf

Stack backtrace:
   0: _wasmer_vm_raise_trap
   1: _wasmer_vm_raise_trap
   2: _napi_register_module_v1
   3: _napi_register_module_v1
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: <unknown>
  13: <unknown>
  14: <unknown>
  15: <unknown>', crates/swc/src/plugin.rs:212:14
stack backtrace:
   0:        0x121b410b0 - _wasmer_vm_raise_trap
   1:        0x121b600cc - _wasmer_vm_raise_trap
   2:        0x121b3cd18 - _wasmer_vm_raise_trap
   3:        0x121b42848 - _wasmer_vm_raise_trap
   4:        0x121b425b0 - _wasmer_vm_raise_trap
   5:        0x121b42cdc - _wasmer_vm_raise_trap
   6:        0x121b42c10 - _wasmer_vm_raise_trap
   7:        0x121b4158c - _wasmer_vm_raise_trap
   8:        0x121b42968 - _wasmer_vm_raise_trap
   9:        0x121c0a4b8 - _wasmer_vm_raise_trap
  10:        0x121c0a55c - _wasmer_vm_raise_trap
  11:        0x120752914 - <unknown>
  12:        0x1205bff20 - <unknown>
  13:        0x1206c2430 - <unknown>
  14:        0x120818b00 - <unknown>
  15:        0x1206c3420 - <unknown>
  16:        0x120817ad8 - <unknown>
  17:        0x1202a3fa0 - <unknown>
  18:        0x1202a9900 - <unknown>
  19:        0x1201d6a24 - <unknown>
  20:        0x1202a0f04 - <unknown>
asset [email protected] 2.32 KiB [emitted] [immutable] [javascript module] (name: main)
./src/entry/bundle.tsx 39 bytes [built] [code generated] [1 error]

If I remove the plugin from the .swcrc file, the whole process runs fine. As soon as I add in a plugin (I have tried Relay and Jest), this issue occurs.

aegooby avatar Jul 04 '22 00:07 aegooby

cc @kwonoj

kdy1 avatar Jul 04 '22 03:07 kdy1

I think we need an example input file can reproduce. Or is it occurs on any source as an input?

kwonoj avatar Jul 04 '22 04:07 kwonoj

I made a demo here: https://github.com/aegooby/swc-webpack-with-plugins

aegooby avatar Jul 04 '22 21:07 aegooby

I have a repo with storybook that builds fine, but doesn't work when storybook tries to run. Maybe connected with this as storybook uses webpack as it's bundler.

Caused by:
    0: failed to invoke `@swc/plugin-emotion` as js transform plugin at node_modules/@swc/plugin-emotion/swc_plugin_emotion.wasm
    1: RuntimeError: out of bounds memory access
    2: heap_get_oob

here's the repo, very minimal - one component

https://github.com/alekangelov/emotion-swc-storybook-bug

yarn storybook fails, but yarn storybook:build succeeds, which is weird

alekangelov avatar Aug 05 '22 22:08 alekangelov

heap_get_oob

this issue is a separate one, upstream issue filed at https://github.com/swc-project/swc/issues/5406

kwonoj avatar Aug 06 '22 03:08 kwonoj

I saw you already deduced that I've got apple silicon. If there's anything I can do, I will 👍

meanwhile will try to repro on: Windows 11 and Ubuntu (WSL and Vanilla)

alekangelov avatar Aug 06 '22 07:08 alekangelov

This is old issue and we've updated lot of internals. Please try with the latest, and report new if it still occurs.

kwonoj avatar Apr 25 '23 20:04 kwonoj