Skip to content

dx serve --release fails to include dioxus-internal JS scripts in certain cases where wasm-bindgen is used #4440

@netthier

Description

@netthier

Problem

When compiling a project using wasm-bindgen's raw_module attribute in release mode, the minification step seemingly fails and certain scripts end up missing from the assets, leading to the page not working as intended.

If the code is changed to make wasm-bindgen include the snippet itself through module and the dioxus asset management of the script is removed, the page works as expected and the scripts that failed to load previously aren't even being requested.
However, this workaround is undesirable in my project.

Steps To Reproduce

Steps to reproduce the behavior:

  • Create a minimal dioxus project like this:
// src/main.rs
use dioxus::prelude::*;
use wasm_bindgen::prelude::*;

const BINDINGS_JS: Asset = asset!(
    "/assets/bindings.js",
    AssetOptions::js().with_hash_suffix(false)
);

fn main() {
    dioxus::launch(App);
}

#[component]
fn App() -> Element {
    use_effect(|| {
        Foo::new();
    });
    rsx! {}
}

#[wasm_bindgen(raw_module = "/assets/bindings.js")]
extern "C" {
    #[wasm_bindgen]
    pub type Foo;
    #[wasm_bindgen(constructor)]
    pub fn new() -> Foo;
}
# Cargo.toml
[package]
# etc.

[dependencies]
dioxus = { version = "0.7.0-alpha.3", features = ["router", "fullstack"] }
wasm-bindgen = "=0.2.100"

[features]
default = ["web"]
# etc., as generated by the jumpstart template
// assets/bindings.js
export class Foo {
  constructor() {}
}
  • Try serving it using dx serve --release
  • Observe 'Failed to minify js. Falling back to non-minified: failed to bundle javascript with swc' errors in the CLI console and failures when loading scripts in the browser (see screenshots below). Relevant section of the logs with verbose+trace: https://paste.debian.net/hidden/2bc6f13f/ (the CLI outputs a lot, please let me know if I should provide the full logs)

Interestingly, the requests in this reproduction all return 200, but with the main pages HTML, while in my actual project where I first encountered the issue the same paths return 404.
Either way they don't contain the necessary scripts and the page fails to load.

Expected behavior

I'd expect similar behaviour to running the page in debug mode, which just works and correctly serves the included scripts.

Screenshots

Image Image Image

(^note the 0B size due to the request being aborted. if the path is requested through curl I get the index.html instead)

Image

(^screenshot from my own project)

Environment:

  • Dioxus version: 0.7.0-alpha.3
  • Rust version: 1.88.0
  • OS info: NixOS 25.05
  • App platform: web

Additional context:
This issue was first discussed on Discord: https://discord.com/channels/899851952891002890/1395874448606757035

The issue affects my project here: https://codeberg.org/bikeshedding-pad/pad as of f3d1f0da63

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcliRelated to the dioxus-cli program

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions