swc-project / plugins

Plugins for swc, written in rust
Apache License 2.0
335 stars 56 forks source link

`@swc/plugin-formatjs` fails to process some symbols #372

Open r34son opened 2 days ago

r34son commented 2 days ago

Describe the bug @swc/plugin-formatjs fails to process some symbols

Expected behavior Expected to not panic at special characters

Additional context Plugins panics at 'О' symbol in Next.js project (version 15.0.3 btw)

thread '<unnamed>' panicked at crates/swc_icu_messageformat_parser/src/parser.rs:1738:21:
byte index 36 is not a char boundary; it is inside 'О' (bytes 35..37) of `© {publishYear}–{currentYear} ООО «<link>ACME</link>»`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
FATAL: An unexpected Turbopack error occurred. Please report the content of /var/folders/vz/06m5nnmd1nj3dkrnv29mk4rsgw0thp/T/next-panic-81f65b1492abdc428d3347b25bb7968e.log, along with a description of what you were doing when the error occurred, to https://github.com/vercel/next.js/issues/new
Failed to compile.

...
Error: failed to process failed to invoke plugin: failed to invoke plugin on 'Some("...")'

Caused by:
    0: failed to invoke `.cache/pnpm-virtual-store/@swc+plugin-formatjs@1.0.1/node_modules/@swc/plugin-formatjs/swc_plugin_formatjs.wasm` as js transform plugin at .cache/pnpm-virtual-store/@swc+plugin-formatjs@1.0.1/node_modules/@swc/plugin-formatjs/swc_plugin_formatjs.wasm
    1: failed to run Wasm plugin transform. Please ensure the version of `swc_core` used by the plugin is compatible with the host runtime. See the documentation for compatibility information. If you are an author of the plugin, please update `swc_core` to the compatible version.

                       Note that if you want to use the os features like filesystem, you need to use `wasi`. Wasm itself does not have concept of filesystem.

                       https://swc.rs/docs/plugin/selecting-swc-core

                       See https://plugins.swc.rs/versions/from-plugin-runner/4.0.0 for the list of the compatible versions.

                       Build info: 
                           Date: 2024-11-07
                           Timestamp: 2024-11-07T09:53:12.683840000Z

                       Version info: 
                           swc_plugin_runner: 4.0.0
                           Dependencies: anyhow 1.0.93,codspeed-criterion-compat 2.7.2,criterion 0.5.1,enumset 1.1.5,futures 0.3.31,once_cell 1.20.2,parking_lot 0.12.3,serde 1.0.214,serde_json 1.0.132,swc_atoms 2.0.0,swc_common 4.0.0,swc_css_ast 4.0.1,swc_css_parser 4.0.0,swc_ecma_ast 4.0.1,swc_ecma_loader 4.0.0,swc_ecma_parser 5.0.0,swc_ecma_visit 4.0.0,swc_malloc 1.0.0,swc_plugin_proxy 4.0.0,testing 4.0.0,tokio 1.41.0,tracing 0.1.40,vergen 9.0.1,virtual-fs 0.16.0,wasmer 4.3.7,wasmer-cache 4.3.7,wasmer-compiler-cranelift 4.3.7,wasmer-wasix 0.27.0

    2: RuntimeError: unreachable

Stack backtrace:
   0: _napi_register_module_v1
   1: _BrotliDecoderVersion
   2: _BrotliDecoderVersion
   3: _BrotliDecoderVersion
   4: _BrotliDecoderVersion
   5: _BrotliDecoderVersion
   6: _BrotliDecoderVersion
   7: _BrotliDecoderVersion
   8: _BrotliDecoderVersion
   9: _BrotliDecoderVersion
  10: _BrotliDecoderVersion
  11: <unknown>
  12: <unknown>
  13: _BrotliDecoderVersion
  14: _BrotliDecoderVersion
  15: _BrotliDecoderVersion
  16: _BrotliDecoderVersion
  17: _BrotliDecoderVersion
  18: <unknown>
  19: <unknown>
  20: <unknown>
  21: <unknown>
  22: <unknown>
  23: <unknown>
  24: <unknown>

Stack backtrace:
   0: _napi_register_module_v1
   1: _napi_register_module_v1
   2: <unknown>
   3: <unknown>

Issue comes from here: https://github.com/swc-project/plugins/blob/c32892add0037ee28a1cab33a946aa6d1c6975b6/crates/swc_icu_messageformat_parser/src/parser.rs#L1738

r34son commented 2 days ago

Hi @kdy1! Also it`s strange that log contains FATAL: An unexpected Turbopack error occurred. Please report the content of /var/folders/vz/06m5nnmd1nj3dkrnv29mk4rsgw0thp/T/next-panic-81f65b1492abdc428d3347b25bb7968e.log, along with a description of what you were doing when the error occurred, to https://github.com/vercel/next.js/issues/new Failed to compile., but i don`t use turbopack already. Seems like issue in next itself. It would be great to show it to someone from Next team.

r34son commented 2 days ago

Something similar was posted here https://github.com/swc-project/plugins/issues/367