ReferenceError: window is not defined
See original GitHub issueI’m getting this error while trying to follow Ari’s tutorial.
ReferenceError: window is not defined
at /home/drstein/projects/react-tests/node_modules/google-maps-react/dist/lib/ScriptCache.js:20:21
at Object.defineProperty.value (/home/drstein/projects/react-tests/node_modules/google-maps-react/dist/lib/ScriptCache.js:5:9)
at Object.<anonymous> (/home/drstein/projects/react-tests/node_modules/google-maps-react/dist/lib/ScriptCache.js:13:3)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.defineProperty.value (/home/drstein/projects/react-tests/node_modules/google-maps-react/dist/GoogleApiComponent.js:5:66)
at Object.<anonymous> (/home/drstein/projects/react-tests/node_modules/google-maps-react/dist/GoogleApiComponent.js:13:3)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
/home/drstein/projects/react-tests/tools/runServer.js:80
throw new Error(`Server terminated unexpectedly with code: ${ code } signal: ${ signal }`);
^
Error: Server terminated unexpectedly with code: 1 signal: null
at ChildProcess.server.once (/home/drstein/projects/react-tests/tools/runServer.js:54:17)
at ChildProcess.g (events.js:292:16)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
error Command failed with exit code 1.
This is my MapLocation.js:
import React from 'react';
import withStyles from 'isomorphic-style-loader/lib/withStyles';
import {Map, GoogleApiWrapper} from 'google-maps-react';
import s from './MapLocation.css';
export class MapLocation extends React.Component {
render () {
if (!this.props.loaded) {
return (<div>Loading...</div>)
}
return (<div> Hello </div>)
}
}
export default GoogleApiWrapper({
apiKey: __GAPI_KEY__
})(MapLocation)
Any ideas? Thank you very much.
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
How to solve "window is not defined" errors in React and ...
First solution: typeof Because typeof won't try to evaluate "window", it will only try to get its type, in our case in Node....
Read more >referenceerror: window is not defined, how to solve
Here's how to fix the “referenceerror: window is not defined” error that you might have in Node.js or with a tool like Next.js....
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 >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 >ReferenceError : window is not defined at object. ...
Well, that file seems to be running on the server, not the browser, and there is no window on the server? Node does...
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
After manually changing
var google = typeof window !== 'undefined' && window.google || null;
, I get this error:@GreatScot yeah the map doesn’t render on the server in this case. But in my case it is only a small part of a big page and I don’t really care if it is not rendered on the server as long as server side rendering works in general.