Trying to load vtk.js dynamically

I’m stuck on the following problem: I want to load vtk.js dynamically but I cannot get it to work (it does work sometimes - which makes the issue rather mysterious for me). Here is what I’m trying:

new Promise(function(resolve, reject) {
	var script = document.createElement("script");
	script.onload = resolve;
	script.onerror = reject;
	script.src = "";
}).then(() => {

The code obviously works in jsfiddle. I already asked on the vtk.js forum (Loading vtk.js dynamically - Web - VTK). Is there something obvious I’m missing here?

BTW: If anyone is interested, I’m trying to implement rendering of cadquery models using vtk.js in jupyter notebooks:

This seems to work. I’d really would like to understand why…

new Promise(function(resolve, reject) {
        "paths": {"vtk": ""},
    require(["vtk"], resolve);
}).then(() => {
    console.log("Loaded vtk.js library");