Kekule.js icon indicating copy to clipboard operation
Kekule.js copied to clipboard

Cannot get ChemWidget in Nodejs

Open joshuaquek opened this issue 4 years ago • 2 comments

My JS code in Nodejs (v10.0.0):

const Kekule = require('kekule').Kekule
console.log(Kekule.ChemWidget)
const chemViewer = new Kekule.ChemWidget.Viewer(document)
console.log(chemViewer)

The problem/output I am getting:

undefined
TypeError: Cannot read property 'Viewer' of undefined 

Any help?

joshuaquek avatar Nov 21 '19 08:11 joshuaquek

Hi @joshuaquek, the widget/chemWidget modules are not loaded in node.js environment by default, since the HTML widgets are useless in server side. Anyway, if they are really needed, you can load the modules in node manually:

const Kekule = require('kekule').Kekule;
Kekule.modules(['chemWidget'], function(error){
  if (!error)    // loading successfully
  {
    console.log(Kekule.ChemWidget.Viewer);
  }
});

Please check the latest dist files. However, there is no window or document object in node.js environment, so the widgets still can not be created and run properly.

partridgejiang avatar Nov 27 '19 14:11 partridgejiang

I see, let me give it a try and I'll be able to report back here again

joshuaquek avatar Dec 03 '19 03:12 joshuaquek