How to solve " Reference Error : windoes not defined" ?

984 views
Skip to first unread message

lenin.mu...@gmail.com

unread,
Dec 30, 2015, 4:34:37 AM12/30/15
to c3js
hi all,
im trying to create a chart with jade and node.js. but i executed the code im getting error as Reference error : window not defined. i want to know how to solve this issue.
Thanks in advance.

Lenin Muthu kumar

unread,
Dec 30, 2015, 5:27:50 AM12/30/15
to c3js
/root/uday/nodejs/jade/node_modules/c3/c3.js:7303
})(window);
   ^
ReferenceError: window is not defined
    at Object.<anonymous> (/root/uday/nodejs/jade/node_modules/c3/c3.js:7303:4)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/root/uday/nodejs/jade/chart_test.js:1:72)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)

Ali Tavakoli

unread,
Dec 30, 2015, 7:44:35 PM12/30/15
to c3js
The error is because there is no window object in node.js, since it's not running in a browser. You can try substituting the "global" object where "window" is used in the source code, but odds are it won't work the way you expect.

In general, I don't think c3.js is meant to generate server-side charts. Can you have your client code source c3.js & generate the charts instead? If it really is a server-side operation you need (e.g. you're trying to generate static images of charts, or you're running tests), you can use PhantomJS + phantomjs-node to mock a browser (and take screenshots, run unit tests, etc...). Either way, it'll need to be the "client" that loads c3.js and generates charts, not node.js.
Reply all
Reply to author
Forward
0 new messages