pmndrs / swc-jotai

MIT License
90 stars 14 forks source link

`Segmentation fault` when running `vite dev` #11

Closed samchouse closed 1 year ago

samchouse commented 1 year ago

I'm using Vite with the React SWC plugin.

import react from "@vitejs/plugin-react-swc";
import * as fs from "fs";
import { defineConfig } from "vitest/config";

const CERT_PATH = "../certs/cert.pem";
const KEY_PATH = "../certs/key.pem";

export default defineConfig({
  plugins: [
    react({
      plugins: [
        ["@swc-jotai/react-refresh", {}],
        ["@swc-jotai/debug-label", {}],
      ],
    }),
  ]
});

I navigate to the dev URL and I get Segmentation fault and vite dev crashes.

Thisen commented 1 year ago

Can you provide a reproduction?

samchouse commented 1 year ago

Just create a Vite app using the SWC version of the React plugin and add Jotai's plugins. Basically just copy the config I provided. Then run dev and visit the server URL.

samchouse commented 1 year ago

For a more detailed guide:

npm create vite@latest demo # Select React as the framework and TypeScript + SWC as the variant.

image

Install the swc-jotai plugins and the copy this config into vite.config.ts:

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react({
      plugins: [
        ["@swc-jotai/debug-label", {}],
        ["@swc-jotai/react-refresh", {}],
      ],
    }),
  ],
});

Run yarn dev. This vanilla example doesn't segfault for me but it still errors and doesn't render with the following:

thread '<unnamed>' panicked at 'assertion failed: prev.start > max', /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmer-compiler-3.2.0-beta.2/src/engine/trap/frame_info.rs:224:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failed to handle: assertion failed: prev.start > max
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: PoisonError { .. }', /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmer-compiler-3.2.0-beta.2/src/engine/trap/frame_info.rs:220:39
Thisen commented 1 year ago

Can you try it out with latest versions of the plugins?

samchouse commented 1 year ago

Now I get this.

[client] thread '<unnamed>' panicked at 'assertion failed: prev.start > max', /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmer-compiler-3.2.0/src/engine/trap/frame_info.rs:224:9
[client] note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[client] failed to handle: assertion failed: prev.start > max
[client] thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: PoisonError { .. }', /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmer-compiler-3.2.0/src/engine/trap/frame_info.rs:220:39
[client] failed to handle: called `Result::unwrap()` on an `Err` value: PoisonError { .. }
[client] thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: PoisonError { .. }', /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmer-compiler-3.2.0/src/engine/trap/frame_info.rs:220:39
[client] failed to handle: called `Result::unwrap()` on an `Err` value: PoisonError { .. }
[client] thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: PoisonError { .. }', /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmer-compiler-3.2.0/src/engine/trap/frame_info.rs:220:39
[client] failed to handle: called `Result::unwrap()` on an `Err` value: PoisonError { .. }
[client] thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: PoisonError { .. }', /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmer-compiler-3.2.0/src/engine/trap/frame_info.rs:220:39
[client] thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: PoisonError { .. }', /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmer-compiler-3.2.0/src/engine/trap/frame_info.rs:220:39
Thisen commented 1 year ago

@Xenfo can you test whether @swc/plugin-noop works in your setup? https://github.com/swc-project/plugins/blob/main/packages/noop/package.json

samchouse commented 1 year ago

No it doesn't, because of this I think this is actually a problem with the SWC plugin for Vite. I'll check if anything is filed upstream.

samchouse commented 1 year ago

https://github.com/vitejs/vite-plugin-react-swc/issues/97

samchouse commented 1 year ago

@swc/plugin-noop works now, it was an issue with my monorepo setup. I checked and confirmed that swc-jotai plugins are still broken, even on a newly generated Vite project.

Thisen commented 1 year ago

Alright, thanks for confirming @Xenfo.

Please provide a reproduction in CodeSandbox or a cloneable repo. Then I can look into it.

Thisen commented 1 year ago

Actually, this is an issue in Wasmer: https://github.com/wasmerio/wasmer/issues/3793

pawelblaszczyk5 commented 1 year ago

Hello, Here is the minimal reproduction with clean Vite + SWC setup: https://github.com/pawelblaszczyk5/swc-jotai-repro

It indeed seems to be some issue inside of wasmer, at least from stacktrace

thread '<unnamed>' panicked at 'assertion failed: prev.start > max', /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmer-compiler-3.2.0/src/engine/trap/frame_info.rs:224:9

KDederichs commented 1 year ago

It does seem to do the same thing on NextJS btw (13.4.8)

thread '<unnamed>' panicked at 'failed to invoke plugin: failed to invoke plugin on 'Some("<path>/node_modules/.pnpm/next@13.4.8_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/client/components/error-boundary.js")'

Caused by:
    0: failed to invoke `<path>/node_modules/.pnpm/@swc-jotai+react-refresh@0.0.8/node_modules/@swc-jotai/react-refresh/swc_jotai_react_refresh.wasm` as js transform plugin at <path>/node_modules/.pnpm/@swc-jotai+react-refresh@0.0.8/node_modules/@swc-jotai/react-refresh/swc_jotai_react_refresh.wasm
    1: RuntimeError: unreachable
           at <unnamed> (<module>[1929]:0x96f9f)
           at <unnamed> (<module>[1924]:0x96d63)
           at <unnamed> (<module>[1923]:0x96d32)
           at <unnamed> (<module>[1910]:0x95ed2)
           at <unnamed> (<module>[1909]:0x95dff)
           at <unnamed> (<module>[1918]:0x965d4)
           at <unnamed> (<module>[2051]:0xa4552)
           at <unnamed> (<module>[2099]:0xaaf0c)
           at <unnamed> (<module>[314]:0x3ffcf)
           at <unnamed> (<module>[100]:0x18ea2)
           at <unnamed> (<module>[123]:0x206cf)
           at <unnamed> (<module>[124]:0x20f28)
           at <unnamed> (<module>[99]:0x18a79)
           at <unnamed> (<module>[97]:0x17a1a)
           at <unnamed> (<module>[123]:0x20aae)
           at <unnamed> (<module>[47]:0x7e77)
           at <unnamed> (<module>[19]:0x1b86)
           at <unnamed> (<module>[17]:0x1aae)
           at <unnamed> (<module>[16]:0x189a)
           at <unnamed> (<module>[347]:0x4993b)
           at <unnamed> (<module>[2195]:0xb1617)', /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swc-0.263.26/src/plugin.rs:162:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread '<unnamed>' panicked at 'failed to invoke plugin: failed to invoke plugin on 'Some("<path>/node_modules/.pnpm/next@13.4.8_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/app-render/entry-base.js")'

the noop plugin works just fine

thecuvii commented 1 year ago

Looks like https://github.com/wasmerio/wasmer/issues/3793 has been fixed.

Thisen commented 1 year ago

Looks like wasmerio/wasmer#3793 has been fixed.

Thanks for the reminder! I'll look into updating the crates soon.

masterbater commented 1 year ago

wen fix?

ornakash commented 1 year ago

Looks like wasmerio/wasmer#3793 has been fixed.

Thanks for the reminder! I'll look into updating the crates soon.

Thank you!

Thisen commented 1 year ago

Sorry for the wait people! Holiday season is over in Europe and I had the time to look into this.

I have published both packages in 0.1.0, hopefully the issues are fixed. If not, create a new issue.