ReferenceError: window is not defined

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,
});

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store