Yew: Counter example: Component expected 1 argument .... and other similar errors

Created on 18 Sep 2018  路  9Comments  路  Source: yewstack/yew

Description

I'm trying to compile the counter example with the official rust-webpack-template.

But it's crashing because Renderable, Component and Html all miss 1 argument.
And ComponentLink is missing, I don't know how and where to import it (in the sources, it is in yew::html::ComponentLink) but can't use it in code.

Cargo.toml, main.rs and counter.rs could be found in the Gist bellow.

Actual Results

The report

Context (Environment)

  • Rust: v1.29.0 (nightly)
  • yew: v0.4.0
  • target: wasm32-unknown-unknown

Most helpful comment

It looks like you used the documentation of the master branch (yew 0.5.0) that is not matching your yew dependency (0.4.0).

Alternatively use the old documentation (https://github.com/DenisKolodin/yew/blob/0.4.0/README.md) or use the unstable master branch by editing Cargo.toml:

[dependencies]
yew = { git = "https://github.com/DenisKolodin/yew.git" }

All 9 comments

It looks like you used the documentation of the master branch (yew 0.5.0) that is not matching your yew dependency (0.4.0).

Alternatively use the old documentation (https://github.com/DenisKolodin/yew/blob/0.4.0/README.md) or use the unstable master branch by editing Cargo.toml:

[dependencies]
yew = { git = "https://github.com/DenisKolodin/yew.git" }

Thank you, I'll check this and come back with some news.

Hello,

Sorry for the late reply.

I so change yew to the git master branch.
But for now, I have another problem. Webpack successfully starts and builds the project but when I start my browser and I have a new error.

I have an error related to env: Can't resolve 'env' in '/Users/scorsi/Code/rust-wasm-test/crate/pkg'.

Here the steps and errors : https://gist.github.com/scorsi/f5186c9f24a851107f7c62226d772d19#file-with-yew-on-master-branch.

My JS juste include code like (with correct path):

import("../crate/pkg").then(module => {
  module.main();
});

And the JS generated by wasm-pack:

/* tslint:disable */
import * as wasm from './rust_webpack_bg';

/**
* @returns {void}
*/
export function main() {
    return wasm.main();
}

export/import aren't available on browser, right ? How could I did that ?

I unfortunately don't know much about rust-webpack-template, as I've only used Yew with cargo-web so far.

Ok, so how do you did that without rust-webpack-template ?

To run the counter example using cargo web:

cargo install cargo-web
cd yew/examples/counter
cargo +nightly web start --target=wasm32-unknown-unknown

This will use the target wasm32-unknown-unknown, which requires the nightly build of rustc.


There are alternative targets that work on Rust stable:

  • asmjs-unkown-emscripten (the default one, that will be used if no target is specified in the command line)
  • wasm32-unknown-emscripten

Both require Emscripten to be installed on your machine. To install Emscripten, follow the steps described here, until "Let鈥檚 create the project.".

Then, running the project should be:

cargo web start

or

cargo web start --target=wasm32-unknown-emscripten

Ok thank you, it works as a charm.
But I'll stop using Yew cause of its poorly performances.
While WASM didn't natively bind Javascript standard library, its performance will be very bad cause of the glue used to manipulate the DOM.

Glad I could help! BTW, I am a ch'ti too, but an expat also :)

Haha, happy to see some french guys right here, we can't go wrong: "Florent B茅cart" is very french ! :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

djahandarie picture djahandarie  路  3Comments

kellytk picture kellytk  路  3Comments

agausmann picture agausmann  路  3Comments

nixpulvis picture nixpulvis  路  4Comments

ghost picture ghost  路  5Comments