window is undefined
See original GitHub issueI created an entire new project with a server.js
containing a single line:
var chartjs = require('chart.js');
and a package.json
with a dependency on chart.js
. Running node server.js
produces the following error:
alex@alex-pc ~/repos/temp2 $ node server.js
/home/alex/repos/temp2/node_modules/chart.js/Chart.js:668
return window.requestAnimationFrame ||
^
ReferenceError: window is not defined
at /home/alex/repos/temp2/node_modules/chart.js/Chart.js:668:11
at Object.<anonymous> (/home/alex/repos/temp2/node_modules/chart.js/Chart.js:676:5)
at Object.<anonymous> (/home/alex/repos/temp2/node_modules/chart.js/Chart.js:2021:4)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/home/alex/repos/temp2/server.js:1:77)
Clearly the problem is mine, because if this was a universal problem then nobody would be able to use this package at all. Anybody got any ideas?
Node v0.12.7 npm v2.11.3
Issue Analytics
- State:
- Created 8 years ago
- Comments:9
Top Results From Across the Web
Javascript: 'window' is not defined - Stack Overflow
The window object represents an open window in a browser. Since you are not running your code within a browser, but via Windows...
Read more >How to solve "window is not defined" errors in React and Next.js
js world, window is not defined, window is only available in browsers. There are three ways to solve that: 1. First solution: typeof....
Read more >ReferenceError: window is not defined in JavaScript
The "ReferenceError: window is not defined" error occurs for multiple reasons: ... The window represents a window containing a DOM document and is...
Read more >How To Solve ReferenceError window is not defined in ...
Fixing a window is not defined error can be quite simple. In most cases, all you will need to do is wrap your...
Read more >[Solved] ReferenceError : window is not defined - ItsJavaScript
The ReferenceError : window is not defined error mainly occurs if you are using the window object in Node.js, React.js, Next.js.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi! I’m using chart.js in a Node.js project, not a browser. My idea is save a chart in an png. I use node-canvas dependency to do it. And I get the same error than you.
I solved it by using:
Hope this could be useful for someone.
If you use webpack like me, then in your webpack.config.js for your server so that
require('chart.js')
gets transpiled to something else and not imported serverside.Of course you have to make sure that chart.js is then only executed on the client side (if you use react then
componentDidMount()
would be a candidate)