Przeglądaj źródła

Update index.js

Lutz Roeder 5 lat temu
rodzic
commit
7f5f20f4b9
1 zmienionych plików z 10 dodań i 5 usunięć
  1. 10 5
      source/index.js

+ 10 - 5
source/index.js

@@ -276,11 +276,16 @@ host.BrowserHost = class {
             script.setAttribute('id', id);
             script.setAttribute('type', 'text/javascript');
             script.setAttribute('src', url);
-            script.onload = () => {
-                const exports = window.module.exports;
-                delete window.module;
-                window.__modules__[id] = exports;
-                resolve(exports);
+            script.onload = (e) => {
+                if (window.module && window.module.exports) {
+                    const exports = window.module.exports;
+                    delete window.module;
+                    window.__modules__[id] = exports;
+                    resolve(exports);
+                }
+                else {
+                    reject(new Error('The script \'' + e.target.src + '\' has no exports.'));
+                }
             };
             script.onerror = (e) => {
                 delete window.module;