Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use synchronous feature in node 18 #44

Closed
akitaSummer opened this issue Oct 25, 2023 · 4 comments
Closed

Cannot use synchronous feature in node 18 #44

akitaSummer opened this issue Oct 25, 2023 · 4 comments

Comments

@akitaSummer
Copy link

Hello, I built a project using #43 ,But I can't use synchronous feature in node 18.
This is my project address:
https://github.com/akitaSummer/gm-crypto-wasm

You can open vitest.config.ts file and remove environment: "jsdom"

import { defineConfig } from "vitest/config";
import RollupPluginNodeResolve from "@rollup/plugin-node-resolve";
import RollupPluginCommonjs from "@rollup/plugin-commonjs";
import nodePolyfills from "rollup-plugin-polyfill-node";

export default defineConfig({
  test: {
    // environment: "jsdom",         <--here
    benchmark: { include: ["**/*.{bench,benchmark}.?(c|m)[jt]s?(x)"] },
  },
  // @ts-ignore
  plugins: [RollupPluginCommonjs(), nodePolyfills(), RollupPluginNodeResolve()],
});

You can run:

nvm use 18

pnpm build

pnpm test

it will report:

 FAIL  __tests__/sm2.spec.ts [ __tests__/sm2.spec.ts ]
RuntimeError: unreachable
 ❯ __rust_start_panic wasm:/wasm/00344e5e:1:649745
 ❯ rust_panic wasm:/wasm/00344e5e:1:647862
 ❯ std::panicking::rust_panic_with_hook::h3aa054d35a0817d7 wasm:/wasm/00344e5e:1:537480
 ❯ std::panicking::begin_panic_handler::{{closure}}::h2f73e4cf6cd6319a wasm:/wasm/00344e5e:1:580900
 ❯ std::sys_common::backtrace::__rust_end_short_backtrace::h98ac61a6abbff7e9 wasm:/wasm/00344e5e:1:649238
 ❯ rust_begin_unwind wasm:/wasm/00344e5e:1:616751
 ❯ core::panicking::panic_fmt::h3e1dd3d08288569e wasm:/wasm/00344e5e:1:637217
 ❯ rand::rngs::thread::THREAD_RNG_KEY::__init::{{closure}}::he320a06782dc2455 wasm:/wasm/00344e5e:1:573823
 ❯ core::result::Result<T,E>::unwrap_or_else::hfe2295bfa0c537d1 wasm:/wasm/00344e5e:1:415402
 ❯ rand::rngs::thread::THREAD_RNG_KEY::__init::h143f0723d0f32842 wasm:/wasm/00344e5e:1:406640

But if you use node 20, this problem will not report this error.

@Pauan
Copy link
Collaborator

Pauan commented Oct 25, 2023

The synchronous feature is only for Workers.

@akitaSummer
Copy link
Author

In fact, this feature can run in both the main thread of the browser and the main thread of node20.But it doesn't work in node18.

Can this be considered a bug?

@akitaSummer
Copy link
Author

I hope that the user experience of my node18 and node20 users will be consistent.

@Pauan
Copy link
Collaborator

Pauan commented Oct 25, 2023

I hope that the user experience of my node18 and node20 users will be consistent.

Well there's nothing I can do about that, if Node 18 has a bug and Node 20 fixed the bug, then it just won't work in Node 18.

But you shouldn't be using synchronous anyways, since it is only for Workers. And it also makes the Wasm a lot bigger in file size, and also makes it slower.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants