kazzkiq / CodeFlask

A micro code-editor for awesome web pages.
https://kazzkiq.github.io/CodeFlask/
MIT License
1.07k stars 120 forks source link

TypeError: Cannot set property 'editorRoot' of undefined #114

Closed mudgen closed 4 years ago

mudgen commented 4 years ago

I added CodeFlask by adding "https://unpkg.com/codeflask/build/codeflask.min.js" to my webpage.

Then I tried to use it like this:

window.onload = function () {
  const flask = CodeFlask("#editorCode", { language: 'js' });
}

Then I get this error in Chrome:

codeflask.min.js:formatted:608 Uncaught TypeError: Cannot set property 'editorRoot' of undefined
    at d (codeflask.min.js:formatted:608)
    at window.onload (app.js:94)

How can this be fixed?

kazzkiq commented 4 years ago

It looks like you forgot the new before CodeFlask.

Each editor run as a new instance, so the code should be:

window.onload = function () {
  const flask = new CodeFlask("#editorCode", { language: 'js' });
}