Skip to content

Dependency to "env" makes triangle example not run with wasm_bindgen in browser #5480

Open
@vizigr0u

Description

edit: tl;dr: wgpu's dependency to parking_lot 0.11 adds a dependency to instant without its wasm-bindgen feature flag, which causes wasm to have an incorrect dependency to env

Description

The Triangle example compiles with target wasm32-unknown-unknown but doesn't run in the browser using wasm_bindgen.

When adding wasm_bindgen(start) (or just wasm_bindgen) macro to the main in the triangle example,
the generated javascript contains import * as __wbg_star0 from 'env';

When ran, this results in Failed to resolve import "env" from "backend/pkg/backend.js". Does the file exist?

This looks like an issue other crates also had when something broke compatibility with wasm32-unknown-unknown.

Repro steps

The following minimal repro contains code that can be commented out to get the code to run :

https://github.com/vizigr0u/rust-wasm-gl/tree/wgpu-wasm-env-bug/backend

Expected vs observed behavior

When surface.configure(&device, &config); is in the code, the generated javascript starts with import * as __wbg_star0 from 'env'; which gives an error when running.

When this line is removed, the generated javascript doesn't have the line and the program runs fine.

Expected: in either case there shouldn't be a dependency to env.

Extra materials

image

Platform

compile command (found in project root package.json) : wasm-pack build --dev ./backend --target web

target wasm32-unknown-unknown
wgpu 0.19.3
see dependencies used in repro's cargo.toml

❯ cargo --version
cargo 1.77.1 (e52e36006 2024-03-26)
❯ rustc --version
rustc 1.77.1 (7cf61ebde 2024-03-27)

Windows 10 + WSL2

Metadata

Assignees

No one assigned

    Labels

    help requiredWe need community help to make this happen.type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions