rust-webpack-template icon indicating copy to clipboard operation
rust-webpack-template copied to clipboard

Web Worker example

Open dakom opened this issue 6 years ago • 9 comments

Would be helpful to have a web-worker example... I had lots of trouble getting that to load

dakom avatar Sep 21 '18 05:09 dakom

Would you mind sending a PR? What were your troubles?

xtuc avatar Sep 21 '18 07:09 xtuc

Sure - I'm happy to fork/adapt to make a web-worker example.

Though when I tried with this repo, just as-is, I got:

error[E0277]: the trait bound `&mut syn::Field: quote::ToTokens` is not satisfied
   --> /Users/davidk/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-macro-support-0.2.21/src/parser.rs:361:44
    |
361 |                 assert_not_variadic(&opts, &field)?;
    |                                            -^^^^^
    |                                            |
    |                                            the trait `quote::ToTokens` is not implemented for `&mut syn::Field`
    |                                            help: consider removing 1 leading `&`-references
    |
    = help: the following implementations were found:
              <syn::Field as quote::ToTokens>
    = note: required for the cast to the object type `dyn quote::ToTokens`

dakom avatar Sep 21 '18 08:09 dakom

@dakom can you check this issue https://github.com/rustwasm/wasm-bindgen/issues/799 I think it is the same. Run cargo update

sendilkumarn avatar Sep 21 '18 09:09 sendilkumarn

Yep, that fixed that error :)

dakom avatar Sep 21 '18 09:09 dakom

Here you go - I put the changes in its own branch on the fork: https://github.com/dakom/rust-webpack-template/tree/worker-example

dakom avatar Sep 21 '18 09:09 dakom

@dakom awesome, let me have a look 👍

sendilkumarn avatar Sep 21 '18 09:09 sendilkumarn

Thanks! Related discussion fyi: https://github.com/webpack-contrib/worker-loader/issues/144

dakom avatar Sep 21 '18 09:09 dakom

I'm running into the same error when trying to load a wasm-bindgen crate inside a web worker using webpack:

TypeError: Cannot read property '../client-wasm-worker/pkg/client_wasm_worker_bg.wasm' of undefined

This is only after using this workaround for a window is not defined error.

Any help would be greatly appreciated.

scottjmaddox avatar Oct 05 '18 05:10 scottjmaddox

https://github.com/VictorGavrish/rust-wasm-worker-template this is also a worker example!

ashleygwilliams avatar Jan 04 '19 14:01 ashleygwilliams