jetli / create-yew-app

Set up a modern Yew web app by running one command.
https://jetli.github.io/create-yew-app/
Apache License 2.0
164 stars 13 forks source link

Uncaught ReferenceError: __exports is not defined #26

Closed jq170727 closed 1 year ago

jq170727 commented 1 year ago

After creating a new app and starting it with

% yarn create yew-app my-app
% cd my-app
% npm start

The window appears black and the browser console reports this error  static.77de5100.js:116 Uncaught ReferenceError: __exports is not defined at parcelRequire.../node_modules/parcel-plugin-wasm.rs/wasm-loader.js.fs (wasm-loader.js:2:1) at newRequire (static.77de5100.js:47:24) at localRequire (static.77de5100.js:53:14) at parcelRequire.0 (wasm-loader.js:1140:1) at newRequire (static.77de5100.js:47:24) at static.77de5100.js:81:7 at static.77de5100.js:120:3

create-yew-app

wasm-loader.js isn't part of parcel-plugin-wasm.rs. It seems to be generated. Looking at node_modules/parcel-plugin-wasm.rs/wasm-loader.js shows

let wasm;
__exports. __wbg_set_wasm = function(val) {
    wasm = val;
}
...

Manually prepending the following line to the file at the top works around the problem

if (typeof __exports == "undefined") { __exports = {}; }
troelsfr commented 1 year ago

Another work around is to add this to the static/index.html:

<!doctype html>
<html lang="en">
  <head>
    <script>
      if (typeof __exports == "undefined") { __exports = {}; }
    </script>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="./favicon.ico">
    <link rel="stylesheet" href="./styles.scss">
    <title>Yew App</title>
  </head>
  <body>
    <script src="./index.ts"></script>
  </body>
</html>
jetli commented 1 year ago

upgrade to use trunk, npx create-yew-app@0.2.0 my-app