yewstack / yew

Rust / Wasm framework for creating reliable and efficient web applications
https://yew.rs
Apache License 2.0
30.71k stars 1.42k forks source link

panicked at 'cannot call wasm-bindgen imported functions on non-wasm targets' #1366

Closed IThawk closed 4 years ago

IThawk commented 4 years ago

Question

panicked at 'cannot call wasm-bindgen imported functions on non-wasm targets'

What I've tried (optional)

jstarry commented 4 years ago

Can you please provide more details?

IThawk commented 4 years ago

@jstarry

    Finished dev [unoptimized + debuginfo] target(s) in 50.15s
     Running `target\debug\game_of_life.exe`
panicked at 'cannot call wasm-bindgen imported functions on non-wasm targets', C:\Users\llwei\.cargo\registry\src\mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd\js-sys-0.3.41\src\lib.rs:4733:9
error: process didn't exit successfully: `target\debug\game_of_life.exe` (exit code: 101)

Process finished with exit code 101
jstarry commented 4 years ago

What command are you running?

IThawk commented 4 years ago
.cargo/bin/cargo.exe run --color=always --package game_of_life --bin game_of_life
teymour-aldridge commented 4 years ago

You need to include the --target wasm32-unknown-unknown flag.

cargo run is also probably not the command you want (you probably want cargo build).

IThawk commented 4 years ago

@jstarry

D:\workspace\language\rust\yew\examples\todomvc>cargo build --target wasm32-unknown-unknown
   Compiling cfg-if v0.1.10
   Compiling once_cell v1.4.0
   Compiling futures-core v0.3.5
   Compiling futures-sink v0.3.5
   Compiling slab v0.4.2
   Compiling futures-io v0.3.5
   Compiling pin-utils v0.1.0
   Compiling itoa v0.4.6
error[E0463]: can't find crate for `core`
  |
  = note: the `wasm32-unknown-unknown` target may not be installed

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `cfg-if`.

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error[E0463]: can't find crate for `std`
  |
  = note: the `wasm32-unknown-unknown` target may not be installed

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error[E0463]: can't find crate for `std`
  |
  = note: the `wasm32-unknown-unknown` target may not be installed

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error[E0463]: can't find crate for `std`
  |
  = note: the `wasm32-unknown-unknown` target may not be installed

error: could not compile `once_cell`.

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `futures-sink`.

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: could not compile `futures-core`.

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error[E0463]: can't find crate for `core`
  |
  = note: the `wasm32-unknown-unknown` target may not be installed

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error[E0463]: can't find crate for `std`
  |
  = note: the `wasm32-unknown-unknown` target may not be installed

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `pin-utils`.

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: could not compile `slab`.

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error[E0463]: can't find crate for `std`
  |
  = note: the `wasm32-unknown-unknown` target may not be installed

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `futures-io`.

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error[E0463]: can't find crate for `std`
  |
  = note: the `wasm32-unknown-unknown` target may not be installed

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `itoa`.

To learn more, run the command again with --verbose.
IThawk commented 4 years ago
  Installing C:\Users\llwei\.cargo\bin\wasm-pack.exe
   Installed package `wasm-pack v0.9.1` (executable `wasm-pack.exe`)
PS C:\Users\llwei> cargo install wasm-pack
    Updating `https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git` index
     Ignored package `wasm-pack v0.9.1` is already installed, use --force to override
PS C:\Users\llwei>
jstarry commented 4 years ago

@IThawk you'll need to install the wasm32-unknown-unknown target:

rustup target add wasm32-unknown-unknown

IThawk commented 4 years ago

how to run .wasm file?

teymour-aldridge commented 4 years ago

You can’t run it directly – you need to import it from Javascript and then run it.

You can use wasm-pack to automatically generate the boilerplate code to do this.

You might also find the starter templates useful.

https://github.com/yewstack/yew-wasm-pack-template https://github.com/yewstack/yew-wasm-pack-template

https://github.com/yewstack/yew-wasm-pack-minimal https://github.com/yewstack/yew-wasm-pack-minimal

On 6 Jul 2020, at 06:44, liulianwei notifications@github.com wrote:

how to run .wasm file?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/yewstack/yew/issues/1366#issuecomment-654026827, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKFSTPJUNRAYHSL7ALMP3SLR2FQCPANCNFSM4OPNB4IA.

jstarry commented 4 years ago

@IThawk feel free to open a new issue if you get stuck again! Also feel free to join our Discord server: https://discord.gg/VQck8X4

thclark commented 1 year ago

Others who end up here may have tried cargo run on the yew tutorial template, which results in this error. Those n00bs should try trunk serve instead.

JohnAllen commented 1 year ago

@thclark this is exactly what happens. There is a mix of example suggestions and hello world suggestions.

rob commented 1 year ago

Others who end up here may have tried cargo run on the yew tutorial template, which results in this error. Those n00bs should try trunk serve instead.

As a n00b, this is what I needed. Appreciate the help @thclark!

n-ae commented 1 year ago

Can yew support trunk & wasm-bindgen-cli as [dev-dependency]? As it currently requires global installment and I think this is causing slower deployments for the lack of an already resolved Cargo.lock.

boris-schwarz commented 1 year ago

Others who end up here may have tried cargo run on the yew tutorial template, which results in this error. Those n00bs should try trunk serve instead.

Interestingly, I ran cargo run first, which panicked and then after reading carefully again, I ran trunk serve, which also didn't work.

Only after running cargo build --target wasm32-unknown-unknown, the command trunk serve worked.

I am a complete noob in Rust and I'm probably better off continue reading "The Book", but I just wanted to fool around a bit with Yew. Hope it helps anybody.

ThomasBartanen commented 11 months ago

For anyone else having issues. I did do cargo build --target wasm32-unknown-unknown and trunk serve and still had issues. I had to add my project folder as an exception to windows defender as well. Then it worked