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.

Love the new updates, but it broke SSR in NextJS

Here is the error

window is not defined
ReferenceError: window is not defined
    at Object.<anonymous> (/usr/src/app/node_modules/react-google-login/dist/google-login.js:1:250)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.react-google-login (/usr/src/app/.next/server/static/development/pages/webpack:/external "react-google-login":1:1)
    at __webpack_require__ (/usr/src/app/.next/server/static/development/pages/webpack:/webpack/bootstrap:21:1)
    at Module../pages/index.tsx (/usr/src/app/.next/server/static/development/pages/index.js:238:76)
    at __webpack_require__ (/usr/src/app/.next/server/static/development/pages/webpack:/webpack/bootstrap:21:1)
    at Object.4 (/usr/src/app/.next/server/static/development/pages/index.js:416:18)
    at __webpack_require__ (/usr/src/app/.next/server/static/development/pages/webpack:/webpack/bootstrap:21:1)
    at /usr/src/app/.next/server/static/development/pages/webpack:/webpack/bootstrap:89:1
    at Object.<anonymous> (/usr/src/app/.next/server/static/development/pages/index.js:94:10)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:8

github_iconTop GitHub Comments

5reactions
anothericommented, Nov 20, 2018

Here is a workaround i use.

Instead of:

import { GoogleLogin } from 'react-google-login';

use:

// NOTE: workaround we have to use b/c of some SSR problems
const { GoogleLogin } = typeof window === 'object' ? require('react-google-login') : {};
3reactions
usmanp24commented, Dec 4, 2018

Hello! I am using this component with Next js and I found this problem and this solution helped me to solve it, but it always returns other errors like this one:

Warning: React.createElement: type is invalid - expected to string (for built-in components) or a class / function (for composite components) but got: undefined. You likely forgot to export your component from the file it’s defined in, or you might have mixed up default and named imports.

Hi, I have solved this by altering code like this:

import React, {Component} from 'react;
let GoogleLib;
export default class App extends Component {
    constructor () {
        super();
        this.state = { showGoogleBtn: false };
    }
    componentDidMount() {
        GoogleLib = require('react-google-login');
        this.setState({ showGoogleBtn: true });

    }

    render() {
        return (
                    {this.state.showGoogleBtn ?
                        <GoogleLib.GoogleLogin
                            clientId="CLIENT_ID"
                            buttonText="Login"
                            onSuccess={googleLoginSucess}
                            onFailure={googleLoginFail}
                        /> : null
                    }
        );
    }
}

This way only clientside will render the google button.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SSR Motorsports - Motorcycles, Pit Bikes, Dirt Bikes, Scooters ...
SSR Motorsports - Motorcycles, Pit Bikes, Dirt Bikes, Scooters, Side x Side's, ATV's, Mopeds, Electric Vehicles, Benelli- Worldwide Distributor.
Read more >
SSR Wheels|
SSR has always focused on manufacturing precise, lightweight, and strong wheels and will continue this tradition for years to come. Detail · PARTS...
Read more >
Smith Seckman Reid, Inc. (SSR)- Engineering ...
SSR is a leader in providing comprehensive engineering design and facility consulting services that consistently meet and exceed these expectations.
Read more >
SSR - Wikipedia
Solid State Records, a Christian record label; Chevrolet SSR, a Chevrolet small truck; Disney's Saratoga Springs Resort & Spa; Small Screen Rendering, ...
Read more >
SSR Motorsports ATVs, UTVs, SxS, Motorcycles & More
Below you'll find the full line of the SSR dirt bikes, pit bikes, ATVs, scooters and enduros as carry. Click here if you'd...
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