Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
j-devel opened this issue Jun 3, 2020 · 1 comment · Fixed by #2184
Closed

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

j-devel opened this issue Jun 3, 2020 · 1 comment · Fixed by #2184
Labels

Comments

@j-devel
Copy link
Contributor

j-devel commented Jun 3, 2020

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;
...
@j-devel j-devel added the bug label Jun 3, 2020
alexcrichton added a commit to alexcrichton/wasm-bindgen that referenced this issue Jun 3, 2020
We're not using ES modules, so use just a normal script!

Closes rustwasm#2182
@alexcrichton
Copy link
Contributor

Thanks for the report! This is a copy-paste typo where type=module isn't supposed to be there.

alexcrichton added a commit that referenced this issue Jun 3, 2020
We're not using ES modules, so use just a normal script!

Closes #2182
Perseus101 pushed a commit to Perseus101/wasm-bindgen that referenced this issue Jun 7, 2020
We're not using ES modules, so use just a normal script!

Closes rustwasm#2182
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants