question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReferenceError: window is not defined

See original GitHub issue

I’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:closed
  • Created 7 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
smartcriscommented, Aug 29, 2017

After manually changing var google = typeof window !== 'undefined' && window.google || null; , I get this error:

ReferenceError: document is not defined
    at Object.ScriptCache.Cache._scriptTag (D:\apps\freedrive\node_modules\google-maps-react\dist\lib\ScriptCache.js:42:31)
    at D:\apps\freedrive\node_modules\google-maps-react\dist\lib\ScriptCache.js:127:95
    at Array.forEach (native)
    at ScriptCache (D:\apps\freedrive\node_modules\google-maps-react\dist\lib\ScriptCache.js:124:34)
    at defaultCreateCache (D:\apps\freedrive\node_modules\google-maps-react\dist\GoogleApiComponent.js:89:45)
    at new Wrapper (D:\apps\freedrive\node_modules\google-maps-react\dist\GoogleApiComponent.js:114:41)
    at D:\apps\freedrive\node_modules\react-dom\lib\ReactCompositeComponent.js:294:18
    at measureLifeCyclePerf (D:\apps\freedrive\node_modules\react-dom\lib\ReactCompositeComponent.js:75:12)
    at ReactCompositeComponentWrapper._constructComponentWithoutOwner (D:\apps\freedrive\node_modules\react-dom\lib\ReactCompositeComponent.js:293:16)
    at ReactCompositeComponentWrapper._constructComponent (D:\apps\freedrive\node_modules\react-dom\lib\ReactCompositeComponent.js:279:21)
0reactions
Eschoncommented, Oct 4, 2017

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found