workers-rs icon indicating copy to clipboard operation
workers-rs copied to clipboard

🐛 BUG: build wasm filenames not as expected

Open 0x65-e opened this issue 2 years ago • 10 comments

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.

0x65-e avatar Mar 26 '23 21:03 0x65-e

Which version of Wrangler did this work with before? Could you post the contents of your wrangler.toml file?

penalosa avatar Mar 27 '23 14:03 penalosa

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.

0x65-e avatar Mar 27 '23 21:03 0x65-e

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

jspspike avatar Apr 17 '23 15:04 jspspike

any updates or workarounds here?

eli-front avatar May 24 '23 03:05 eli-front

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

eli-front avatar May 24 '23 03:05 eli-front

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.

katopz avatar Jun 19 '23 11:06 katopz

cross posted here: https://github.com/cloudflare/rustwasm-worker-template/issues/41

mimoo avatar Aug 02 '23 17:08 mimoo

Same under linux. I feel like cloudflare workers are abandoned

oriongonza avatar Sep 26 '23 17:09 oriongonza

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

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

cruzluna avatar Feb 24 '24 05:02 cruzluna

@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.

Kakapio avatar Mar 25 '24 02:03 Kakapio