Home > Blockchain >  Go-debug-module.js:15 Uncaught Error: Invalid DIV id; could not get element with id: gojs
Go-debug-module.js:15 Uncaught Error: Invalid DIV id; could not get element with id: gojs

Time:12-27

I use below way to import gojs for my project but failed to find the div.

https://codesandbox.io/s/magical-snowflake-76x31o?file=/src/App.vue

I get error:

Go-debug-module.js:15 Uncaught Error: Invalid DIV id; could not get element with id: gojs

CodePudding user response:

This happens because your DOM element has not been loaded yet by the browser, but the script has, so the script is executing before the element is available.

It appears that you tried to fix this by using init() but that runs right away as well, instead, add an event listener to the window.onload event: window.onload = init;

Or preferably on DOMContentLoaded as it's executed before external sources has been loaded, unlike window.onload.

document.addEventListener("DOMContentLoaded", init);
  • Related