Closed
Description
Describe the Bug
We see an error in Safari when loading the without-a-bundler-no-modules
example.
Steps to Reproduce
git clone https://github.com/rustwasm/wasm-bindgen
cp -r wasm-bindgen/examples/without-a-bundler-no-modules .
cd without-a-bundler-no-modules
wasm-pack build --target no-modules
- 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
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;
...