无法在 Mac m1 上遵循 yew 教程 - 使用未声明的类型“Vec”

met*_*bar 5 rust rust-cargo webassembly yew

每当我运行trunk buildcargo run --target=wasm32-unknown-unknown遇到一堆范围错误时。

\n

在此输入图像描述

\n

我已经运行了rustup target add wasm32-unknown-unknowncargo install --locked wasm-bindgen-cli,但仍然没有运气。

\n

这些错误消息是什么意思?

\n

[编辑]\n输出很长,但它是这样开始的:

\n
[2m2022-06-06T01:51:52.351114Z[0m [32m INFO[0m  starting build\n[2m2022-06-06T01:51:52.351741Z[0m [32m INFO[0m spawning asset pipelines\n[2m2022-06-06T01:51:52.390738Z[0m [32m INFO[0m building yew-app\n   Compiling ryu v1.0.10\n   Compiling itoa v1.0.2\n   Compiling cfg-if v1.0.0\n   Compiling hashbrown v0.11.2\n   Compiling slab v0.4.6\n   Compiling scoped-tls-hkt v0.1.2\n   Compiling serde v1.0.137\n   Compiling thiserror v1.0.31\nerror[E0463]: can\'t find crate for `core`\n  |\n  = note: the `wasm32-unknown-unknown` target may not be installed\n  = help: consider downloading the target with `rustup target add wasm32-unknown-unknown`\n\nerror[E0463]: can\'t find crate for `compiler_builtins`\n\nFor more information about this error, try `rustc --explain E0463`.\nerror: could not compile `cfg-if` due to 2 previous errors\nwarning: build failed, waiting for other jobs to finish...\nerror[E0463]: can\'t find crate for `core`\n  --> /Users/patrickstivalchaerke/.cargo/registry/src/github.com-1ecc6299db9ec823/itoa-1.0.2/src/lib.rs:44:5\n   |\n44 | use core::mem::{self, MaybeUninit};\n   |     ^^^^ can\'t find crate\n   |\n   = note: the `wasm32-unknown-unknown` target may not be installed\n   = help: consider downloading the target with `rustup target add wasm32-unknown-unknown`\n\nerror[E0463]: can\'t find crate for `std`\n  |\n  = note: the `wasm32-unknown-unknown` target may not be installed\n  = help: consider downloading the target with `rustup target add wasm32-unknown-unknown`\n\nerror[E0463]: can\'t find crate for `core`\n  --> /Users/patrickstivalchaerke/.cargo/registry/src/github.com-1ecc6299db9ec823/itoa-1.0.2/src/lib.rs:45:5\n   |\n45 | use core::{ptr, slice, str};\n   |     ^^^^ can\'t find crate\n   |\n   = note: the `wasm32-unknown-unknown` target may not be installed\n   = help: consider downloading the target with `rustup target add wasm32-unknown-unknown`\n\nerror: cannot find macro `debug_assert_eq` in this scope\n  --> /Users/patrickstivalchaerke/.cargo/registry/src/github.com-1ecc6299db9ec823/itoa-1.0.2/src/udiv128.rs:39:5\n   |\n39 |     debug_assert_eq!(quot, n / d as u128);\n   |     ^^^^^^^^^^^^^^^\n\nerror: cannot find macro `debug_assert_eq` in this scope\n  --> /Users/patrickstivalchaerke/.cargo/registry/src/github.com-1ecc6299db9ec823/itoa-1.0.2/src/udiv128.rs:40:5\n   |\n40 |     debug_assert_eq!(rem as u128, n % d as u128);\n   |     ^^^^^^^^^^^^^^^\n\nerror[E0463]: can\'t find crate for `core`\n --> /Users/patrickstivalchaerke/.cargo/registry/src/github.com-1ecc6299db9ec823/ryu-1.0.10/src/buffer/mod.rs:2:5\n  |\n2 | use core::mem::MaybeUninit;\n  |     ^^^^ can\'t find crate\n  |\n  = note: the `wasm32-unknown-unknown` target may not be installed\n  = help: consider downloading the target with `rustup target add wasm32-unknown-unknown`\n\nerror[E0463]: can\'t find crate for `core`\n --> /Users/patrickstivalchaerke/.cargo/registry/src/github.com-1ecc6299db9ec823/ryu-1.0.10/src/buffer/mod.rs:3:5\n  |\n3 | use core::{slice, str};\n  |     ^^^^ can\'t find crate\n  |\n  = note: the `wasm32-unknown-unknown` target may not be installed\n  = help: consider downloading the target with `rustup target add wasm32-unknown-unknown`\n\nerror[E0463]: can\'t find crate for `core`\n  --> /Users/patrickstivalchaerke/.cargo/registry/src/github.com-1ecc6299db9ec823/ryu-1.0.10/src/d2s.rs:27:5\n   |\n27 | use core::mem::MaybeUninit;\n   |     ^^^^ can\'t find crate\n   |\n   = note: the `wasm32-unknown-unknown` target may not be installed\n   = help: consider downloading the target with `rustup target add wasm32-unknown-unknown`\n\nerror[E0433]: failed to resolve: use of undeclared type `MaybeUninit`\n  --> /Users/patrickstivalchaerke/.cargo/registry/src/github.com-1ecc6299db9ec823/itoa-1.0.2/src/lib.rs:80:22\n   |\n80 |         let bytes = [MaybeUninit::<u8>::uninit(); I128_MAX_LEN];\n   |                      ^^^^^^^^^^^ use of undeclared type `MaybeUninit`\n
Run Code Online (Sandbox Code Playgroud)\n

[编辑2]

\n

我看到输出的开头表示我应该考虑安装目标 wasm32-unknown-unknown。

\n

但我确实安装了它。另一个终端输出:

\n
yew-app git:(master) \xe2\x9c\x97 rustup target add wasm32-unknown-unknown\ninfo: component \'rust-std\' for target \'wasm32-unknown-unknown\' is up to date\n\nyew-app git:(master) \xe2\x9c\x97 rustc -V\nrustc 1.59.0\n
Run Code Online (Sandbox Code Playgroud)\n

met*_*bar 10

实际上我分别安装了 homebrew 的 rustup 和 rustup 。我猜他们在一起玩得不好。

我从brew中卸载了rust,重新安装了rustup,安装了wasm-bindgen-cli,添加了目标并且它起作用了。

我运行过的命令列表:

rustup target remove wasm32-unknown-unknown
rustup self uninstall
brew uninstall rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add wasm32-unknown-unknown
cargo install --locked trunk
cargo clean
trunk clean
cargo install --locked wasm-bindgen-cli

# And finally
trunk serve
Run Code Online (Sandbox Code Playgroud)