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.

SSR: ReferenceError: window is not defined

See original GitHub issue

Describe the bug I am testing the new SSR capabilities with next.js and I am seeing:

ReferenceError: window is not defined
    at UniversalStorage.setUniversalItem (/node_modules/@aws-amplify/core/lib/UniversalStorage/index.js:88:21)
    at UniversalStorage.setItem (/node_modules/@aws-amplify/core/lib/UniversalStorage/index.js:69:22)
    at CognitoUser.cacheTokens (/node_modules/amazon-cognito-identity-js/lib/CognitoUser.js:1412:18)
    at /node_modules/amazon-cognito-identity-js/lib/CognitoUser.js:1391:17
    at /node_modules/amazon-cognito-identity-js/lib/Client.js:127:31

To Reproduce Follow steps in tutorial here https://docs.amplify.aws/start/getting-started/data-model/q/integration/next Connect with auth and sign in with cognito.

Expected behavior window is not used on the server.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:20 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
rgksugancommented, Feb 8, 2021

@m5r At this moment, the supported use-case is Auth happening on the client so credentials can be shared with the server.

In your example, you’re attempting to do the authentication on the server, which we’re still solving for. That would make it a feature request, but this use-case seems different than what’s happening for @oste.

@oste #6813 (comment) makes it sound like you were specifying a custom storage adapter. That won’t be necessary with Amplify.configure({ ...awsexports, ssr: true }).

Is Authentication on the server made available now?

1reaction
ericclemmonscommented, Sep 23, 2020

@m5r At this moment, the supported use-case is Auth happening on the client so credentials can be shared with the server.

In your example, you’re attempting to do the authentication on the server, which we’re still solving for. That would make it a feature request, but this use-case seems different than what’s happening for @oste.

@oste https://github.com/aws-amplify/amplify-js/issues/6813#issuecomment-695056643 makes it sound like you were specifying a custom storage adapter. That won’t be necessary with Amplify.configure({ ...awsexports, ssr: true }).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to resolve window is not defined on npm run serve:ssr ...
The issue is caused by package webpack, I think but not sure. Description. The command line : "npm run serve:ssr" occurred the exception...
Read more >
Angular Universal: ReferenceError: window is not defined
This error can be caused by a reference to the Window object if you are rendering your application from a server like Node.js....
Read more >
referenceerror: window is not defined SSR ANGULAR
on SSR, there is no window , because you are on the server, not on the browser. So you have to make your...
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 >
How To Solve ReferenceError window is not defined in ...
If you are specifically working on a Node.js application and still receive this error, it is because the window object does not actually...
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