workers-rs
workers-rs copied to clipboard
🐛 BUG: build wasm filenames not as expected
Which Cloudflare product(s) does this pertain to?
Wrangler
What version of Wrangler are you using?
2.13.0
What operating system are you using?
Windows, WSL and Linux
Describe the Bug
After not running wrangler for a couple months, I tried to deploy and encountered the following error:
> npx wrangler publish --dry-run
⛅️ wrangler 2.13.0
--------------------
Running custom build: cargo install -q worker-build && worker-build --release
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
Finished release [optimized] target(s) in 0.36s
[INFO]: Installing wasm-bindgen...
[INFO]: Optimizing wasm binaries with `wasm-opt`...
[INFO]: Optional fields missing from Cargo.toml: 'description', 'repository', and 'license'. These are not necessary, but recommended
[INFO]: :-) Done in 1.65s
[INFO]: :-) Your wasm pkg is ready to publish at C:\Users\mcrai\Documents\Git Repos\mattcraig.tech\build.
X [ERROR] Could not resolve "./index_bg.wasm"
index_bg.js:1:22:
1 │ import * as wasm from './index_bg.wasm';
╵ ~~~~~~~~~~~~~~~~~
1 error
Error: esbuild exited with status exit code: 1
X [ERROR] Command failed with exit code 1: cargo install -q worker-build && worker-build --release
Looking at the build directory, it appears that index.wasm is being generated but no index_bg.wasm, which is causing esbuild to fail.
I have not made any changes to my code or build configuration, just tried re-running workflows that worked 2 months ago with an updated version of wrangler.
Which version of Wrangler did this work with before? Could you post the contents of your wrangler.toml file?
I was previously on wrangler 2.1.9, but the issue was present on both 2.1.9 and after upgrading to 2.13.0.
It appears the underlying issue was with the worker crate. I was using the v0.0.9, but the wasm-bindgen dependency was still on v0.2.78. The latest version of worker-build, v0.0.9, is only compatible with wasm-bindgen v0.2.84 onwards, which is where the change to wasm import replacement occurs that is causing the resolution to fail. Upgrading to worker v0.0.15 updated the wasm-bindgen dependency to v0.2.84 and fixed the error.
It seems like there's a dependency link missing somewhere in this chain. worker pins the version of wasm-bindgen that it depends on, but worker-build is free to upgrade even when it's no longer compatible with the version of wasm-bindgen used. It seems like worker-build is implicitly depending on a specific version of wasm-bindgen (or a version of worker) that isn't declared as a dependency.
Sorry for the delayed response on this, glad you found the root of the issue. worker and worker-build are managed in the workers-rs repo. So I will transfer this issue there
any updates or workarounds here?
Here's a workaround for those looking. Change your wrangler.toml to specify a build version before 0.0.9
[build]
command = "cargo install -q worker-build --version ^0.0.8 && worker-build --release" # required
same here
macOS 13.4
wrangler 3.1.0
wasm-pack 0.10.3
npx wrangler dev also have this issue, Thanks for workaround btw.
cross posted here: https://github.com/cloudflare/rustwasm-worker-template/issues/41
Same under linux. I feel like cloudflare workers are abandoned
Here's a workaround for those looking. Change your
wrangler.tomlto specify a build version before0.0.9[build] command = "cargo install -q worker-build --version ^0.0.8 && worker-build --release" # required
Yep fixed my issue.
Here is my fixed wrangler.toml:
name = "name"
workers_dev = true
compatibility_date = "2022-01-20"
main = "build/worker/shim.mjs"
[[rules]]
globs = [ "**/*.wasm" ]
type = "CompiledWasm"
[build]
command = "cargo install -q worker-build --version ^0.0.8 && worker-build --release" # required
@kflansburg I believe you should be able to close this now? It looks to me as if this issue no longer exists with the latest version of workers.