Open ibaryshnikov opened 5 years ago
IIRC, because node only has experimental support for modules that you have to enable with a special flag at startup, we don't support modules + js snippets on node unless you set the WBINDGEN_I_PROMISE_JS_SYNTAX_WORKS_IN_NODE
env var, which is just for our own internal testing really.
To properly support js snippets on node, we want to rewrite the exports to common js.
@fitzgen nice, thank you for the response! so it's already on your roadmap?
I would say we know what needs to be done, but have not prioritized it or come up with any target release dates or anything like that. If you want to talk about it next WG meeting, feel free to add to the schedule!
What would help move this issue forward, at least for the no-modules
target?
The original RFC has a bit more information, but there's not much more other than "this needs implementing" for the node/no-modules targets. The "this" in terms of what needs to happen is specified in the RFC.
I made https://github.com/yewstack/yew-wasm-pack-minimal and used Rollup
with the intention of removing it when wasm-pack
can be used exclusively. If it could be modified in any way to assist with implementation please feel welcome to open an issue.
Is there an update on snippets for nodejs?
Does this require "only" implementation and if so, is there a plan for how to do so? Specifically, it seems like there hasn't been a decision on which JS parser to use. I could imagine implementing this, but it depends on how much time it would take.
We currently want to use websocket support from rust-libp2p
that imports a JS snippet to implement it. It seems to be fixed by removing the export
keyword from the websocket_transport
function and adding the line
exports.websocket_transport = websocket_transport;
I assume, however, that a more universal solution would not be as straightforward.
Initially nodejs target was not supported when js snippets were implemented. Is it the time to add support for nodejs?
There is already code like this in
js-sys
tests:https://github.com/rustwasm/wasm-bindgen/blob/master/crates/js-sys/tests/wasm/Iterator.rs#L5
And it somehow works. But when I tried to compile my own module, it compiled and failed in runtime because the
.js
file was not copied to thepkg
folder. How did you make the tests work?