Search code examples
javascriptimportkonvajs

Uncaught TypeError: _konva.default.stage is not a constructor


I'm trying to use KonvaJS and I've chosen to install it via npm. So, as mentioned on https://konvajs.org/docs/index.html I used "npm install konva", everything looked ok. I imported Konva in my index.js like that: import Konva from 'konva';

And my index.js is related to my index.html with a script tag at the end of the body: <script type="text/javascript" src="./index.js"></script>

When I try to parcel index.html, I get an "Uncaught TypeError: _konva.default.stage is not a constructor".

Of course, nothing Konva-related appears on the page, as the error is located at line 5: const stage = new Konva.stage({

I read https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Not_a_constructor but I really don't see where my mistake is. (I also saw https://github.com/konvajs/konva/issues/598 but I don't use TypeScript.)


Solution

  • You need to have Stage with capital S: Konva.Stage