WASM/Yew - failed to resolve: could not find `unix` in `os`

2.9k views Asked by At

Building Yew App on Windows

I'm building a yew app alongside a rocket backend on Windows following this tutorial (although the tutorial is for a Linux environment). I'm trying to build the yew app using wasm-pack. I'm not using the Linux subsystem to build the app, though I do have it installed.

Code / Configuration

The repository.

I have already installed the wasm toolchain and cargo make:

rustup target add wasm32-unknown-unknown

The following is my toolchain list:

stable-x86_64-pc-windows-gnu
stable-x86_64-pc-windows-msvc
nightly-x86_64-pc-windows-msvc (default)
1.30.0-x86_64-pc-windows-msvc

Here is my folder structure:

Project root
├───backend           <-- rocket backend
|   ├───Cargo.toml
│   └───src
│       ├───bin
│       └───db
├───frontend          <-- yew frontend
│   ├───pkg
│   ├───src
|   ├───Cargo.toml
|   └───Makefile.toml
├───src
├───Cargo.toml
└───Makefile.toml

This is rootdir\Cargo.toml:

[package]
name = "sentinel"
version = "0.1.0"
authors = ["zachdelano <email>"]
edition = "2018"

[workspace]
members = ["backend", "frontend"]

This is rootdir\Makefile.toml:

[env]
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = "true"

[tasks.default]
clear = true
dependencies = ["build"]

This is rootdir\frontend\Cargo.toml:

[dependencies]
sentinel = { path = ".." }
yew = "0.17.3"
wasm-pack = "0.9.1"
wasm-bindgen = "0.2.68"
web-sys = "0.3.45"

[lib]
crate-type = ["cdylib", "rlib"]

This is rootdir\frontend\Makefile.toml:

[tasks.default]
dependencies = ["create_wasm"]

[tasks.create_wasm]
command = "wasm-pack"
args = ["build", "--target", "web", "--out-name", "package", "--dev"] 
dependencies = ["build"]

Expected result

I expect the app to finish building with no errors when I run cargo make. The Yew tutorial seems to indicate nothing else is needed.

Actual output

I get a host of errors when running cargo make (from the root directory) like the following:

error[E0433]: failed to resolve: could not find `unix` in `os`
  --> C:\Users\Zach\.cargo\registry\src\github.com-1ecc6299db9ec823\dirs-1.0.5\src\lin.rs:41:18
   |
41 |     use std::os::unix::ffi::OsStringExt;
   |                  ^^^^ could not find `unix` in `os`

See the entire list of errors.

Is this a toolchain sort of thing? How can I fix this?

Running rustup update

I get the following output from running rustup update.

Now when I run cargo make from the root directory, I get different errors:

error[E0432]: unresolved import `crate::sys`                                                                                                                                                                                     
  --> C:\Users\Zach\.cargo\registry\src\github.com-1ecc6299db9ec823\socket2-0.3.15\src\socket.rs:23:5
   |
23 | use crate::sys;
   |     ^^^^^^^^^^ no `sys` in the root

See the full list of errors. Some of the code changed in the repository.

1

There are 1 answers

0
Zachary Delano On BEST ANSWER

The issue ended up being that I was trying to install wasm-pack and web-sys. I don't know why that was an issue but when I commented them out and ran cargo make, everything built just fine. I also deleted target and reran cargo make just to make sure.

[package]
name = "frontend"
version = "0.1.0"
authors = ["zachdelano <email>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
sentinel = { path = ".." }
yew = "0.17.3"
wasm-bindgen = "0.2.68"
# wasm-pack = "0.9.1"
# web-sys = "0.3.45"

[lib]
crate-type = ["cdylib", "rlib"]