cloudflare / workers-rs

Write Cloudflare Workers in 100% Rust via WebAssembly
Apache License 2.0
2.6k stars 279 forks source link

[BUG] Workers-rs projects don't compile locally #626

Closed megaconfidence closed 2 months ago

megaconfidence commented 2 months ago

Is there an existing issue for this?

What version of workers-rs are you using?

0.1.0

What version of wrangler are you using?

3.72.2

Describe the bug

Local build with npx wrangler dev fails with the following error


 ⛅️ wrangler 3.72.2
-------------------

Running custom build: cargo install -q worker-build && worker-build --release
[INFO]: 🎯  Checking for the Wasm target...
[INFO]: 🌀  Compiling to Wasm...
   Compiling worker v0.2.0
error[E0599]: no method named `unwrap` found for struct `js_sys::Iterator` in the current scope
  --> /Users/megaconfidence/.cargo/registry/src/index.crates.io-6f17d22bba15001f/worker-0.2.0/src/headers.rs:83:14
   |
80 | /         self.0
81 | |             .keys()
82 | |             // Header.keys() doesn't error: https://developer.mozilla.org/en-US/docs/Web/API/Headers/keys
83 | |             .unwrap()
   | |             -^^^^^^ method not found in `Iterator`
   | |_____________|
   | 

error[E0599]: no method named `unwrap` found for struct `js_sys::Iterator` in the current scope
  --> /Users/megaconfidence/.cargo/registry/src/index.crates.io-6f17d22bba15001f/worker-0.2.0/src/headers.rs:95:14
   |
92 | /         self.0
93 | |             .values()
94 | |             // Header.values() doesn't error: https://developer.mozilla.org/en-US/docs/Web/API/Headers/values
95 | |             .unwrap()
   | |             -^^^^^^ method not found in `Iterator`
   | |_____________|
   | 

error[E0599]: no method named `unwrap` found for struct `js_sys::Iterator` in the current scope
  --> /Users/megaconfidence/.cargo/registry/src/index.crates.io-6f17d22bba15001f/worker-0.2.0/src/headers.rs:69:14
   |
66 | /         self.0
67 | |             .entries()
68 | |             // Header.entries() doesn't error: https://developer.mozilla.org/en-US/docs/Web/API/Headers/entries
69 | |             .unwrap()
   | |             -^^^^^^ method not found in `Iterator`
   | |_____________|
   | 

error[E0277]: the `?` operator can only be applied to values that implement `Try`
  --> /Users/megaconfidence/.cargo/registry/src/index.crates.io-6f17d22bba15001f/worker-0.2.0/src/http/header.rs:11:16
   |
11 |     for res in from_headers.entries()?.into_iter() {
   |                ^^^^^^^^^^^^^^^^^^^^^^^ the `?` operator cannot be applied to type `js_sys::Iterator`
   |
   = help: the trait `Try` is not implemented for `js_sys::Iterator`

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `worker` (lib) due to 4 previous errors
Error: Compiling your crate to WebAssembly failed
Caused by: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit status: 101
  full command: cd "/Users/megaconfidence/Sandbox/temp/workers-rs" && "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"
Error: wasm-pack exited with status exit status: 1

✘ [ERROR] Running custom build `cargo install -q worker-build && worker-build --release` failed. There are likely more logs from your build command above.

🪵  Logs were written to "/Users/megaconfidence/Library/Preferences/.wrangler/logs/wrangler-2024-08-27_13-51-18_646.log"

Steps To Reproduce

No response

kflansburg commented 2 months ago

This should have been fixed in v0.3.4.

SandroHc commented 2 months ago

Upgrading to worker v0.3.4 fixed the issue for me.

Please note that the templates still point to worker v0.2.0, so any project created with cargo generate cloudflare/workers-rs will fail with this error.