ReferenceError: window is not defined
Nov 2, 2020
Import domino ()// As the name might suggest, domino's goal is to provide a DOM in Node.when using the ts-mxgraph wrapper for mxgraph, the headless chromium from the server doesn't get a browser window and that's where the below patch can rescue.const win = domino.createWindow(template);create a dummy global window and other stuffs as you need from the below list.global['window'] = win;
global['document'] = win.document;
global['DOMTokenList'] = win.DOMTokenList;
global['Node'] = win.Node;
global['Text'] = win.Text;
global['HTMLElement'] = win.HTMLElement;
global['navigator'] = win.navigator;Now the below code should workimport {mxgraphFactory} from 'ts-mxgraph';
const mx = mxgraphFactory({
mxBasePath: 'mxgraph',
mxLoadResources: false,
mxLoadStylesheets: false,
});