Skip to content

Error in Safari when loading without-a-bundler-no-modules example #2182

Closed
@j-devel

Description

@j-devel

Describe the Bug

We see an error in Safari when loading the without-a-bundler-no-modules example.

Steps to Reproduce

  1. git clone https://github.com/rustwasm/wasm-bindgen
  2. cp -r wasm-bindgen/examples/without-a-bundler-no-modules .
  3. cd without-a-bundler-no-modules
  4. wasm-pack build --target no-modules
  5. Statically serve the without-a-bundler-no-modules directory and visit index.html using Safari.

Actual Behavior

The example doesn't load leaving an error in the developer console:

ReferenceError: Can't find variable: wasm_bindgen

Screen Shot 2020-06-03 at 17 27 29

Analysis

By loading generated pkg/without_a_bundler_no_modules.js:

let wasm_bindgen;
...

wasm_bindgen is expected to be globally exported, which works fine in Chrome/Firefox, but not in Safari. In case of Safari, the scoping behavior seems different; the let variable becomes scoped in the <script> block (a relevant case here).

As a workaround, should we update crates/cli-support/src/js/mod.rs so that it generates JS like the following instead?

var wasm_bindgen;
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions