This is because of the way scripts/gadgets load in MediaWiki, with ResourceLoader and dependencies. Not sure if it is possible to solve this?