Skip to content

import.meta.url references absolute file path in production #4758

@mohe2015

Description

@mohe2015

Problem

Hi, bundling with swc_bundler as is the default for production leads to import.meta.url referencing absolute file paths in production which breaks importing based on them. swc-project/swc#7511 seems to have requested to allow disabling this but there was never a response. I couldn't find a workaround.

Steps To Reproduce

Steps to reproduce the behavior:

Dioxus app with:

#[cfg(target_arch = "wasm32")]
#[wasm_bindgen::prelude::wasm_bindgen]
extern "C" {
    // Getters can only be declared on classes, so we need a fake type to declare it on.
    #[wasm_bindgen]
    type meta;

    #[wasm_bindgen(js_namespace = import, static_method_of = meta, getter)]
    fn url() -> String;
}

#[cfg(target_arch = "wasm32")]
#[wasm_bindgen::prelude::wasm_bindgen]
pub fn shim_url() -> String {
    meta::url()
}

info!("{}", shim_url());
  • Build with --release

Expected behavior

import.meta.url should return a correct value.

Screenshots

Environment:

  • Dioxus version: main
  • Rust version: nightly
  • OS info: NixOS 25.05
  • App platform: web

Questionnaire

I'm interested in fixing this myself but don't know where to start.

Metadata

Metadata

Assignees

No one assigned

    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