Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Clarify / define Node.js story #250

@RReverser

Description

@RReverser

Apologies if this was discussed before, but I haven't found any relevant references so far (aside from ESM integration) and felt it's worth discussing publicly.


While I like wasm-pack, wasm-bindgen and companion bindings libraries, I feel that they focus almost solely on the browser side of things.

At the same time, Node.js story doesn't seem to be currently covered very well (neither in prototypes nor plans), despite it being a popular and an interesting platform for running all sorts of mixed JS+Rust executables without resorting to native modules.


First issue is that there exists js-sys for generic JS runtime bindings and there is web-sys with web interfaces for browsers, but I would hope to see something like node-sys for predefined bindings for Node.js built-in modules and objects - process, fs, http just to name a few that would be useful from Rust side.


Second issue is that on the actual execution side there is currently no easy way to actually run them from command-like.

With Emscripten you can simply preconfigure node as a target.wasm32-unknown-emscripten.runner system-wide once and then cargo run and friends will just work, but running WASM produced with wasm32-unknown-unknown is currently much more involved and requires:

  • Manually defining required bindings to e.g. process.argv to read command-line arguments.
  • Adding wasm_bindgen(start) and providing conditionally compiled wrappers to use either argv bindings or std::env::args().
  • Compiling WASM manually using cargo (because wasm-pack expects only cdylib as a crate type).
  • Finding the produced filename (it might be easy for binaries, but examples and such also include hashes so you need to look this up manually).
  • Running wasm-bindgen --nodejs ... on the result.
  • Finally, running the result.
  • On every iteration, repeat from step 3.

For this one, I would hope to see something like wasm-pack run ... that could be used as a target.wasm32-unknown-unknown.runner and would automate all or most of these things above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions