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.

Usage with @aws-amplify next/SSR

See original GitHub issue

Hi there,

🚀 Feature Proposal

While using withSSRContext from @aws-amplify (https://github.com/aws-amplify/amplify-js) in getServerSideProps we get ReferenceError: window is not defined

Should we mock getServerSideProps ?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
toomuchdesigncommented, Dec 24, 2020

A fix is available in #73 which is blocked until Jest v27 gets released.

1reaction
Meemawcommented, Dec 16, 2020

I looked into this and its caused by a very annoying issue we are facing in this library: external modules eagerly evaluating document | window existence on top level (on import). This happens before next-page-tester is in “control” of things and could “wire” it correctly.

@toomuchdesign:

@aws-amplify first checks if its browser environment upon import and that evaluates to true because of JSDOM, and then tries to access localStorage in getServerSideProps which is not available.

I expect this will cause problems with many external libraries and we probably need to find some solution for this. I though about just deleting window and document in our initTestHelpers and then restoring them in getPage which would help in this example, but will break other libraries, e.g. react-hook-form which then won’t work correctly because it will assume its not in JSDOM.

This is not a problem for NextJS where code is executed in 2 different environments (Node + Browser). I think in our case we need to find a reliable way to wipe require.cache after initial “SSR” render and then let JSDOM take over. Unfortunately I don’t know if there is a reliable way to do this since test frameworks are using hacks to “re-implement” require mechanism.

If there is not a reliable cross-framework way we could consider implementing framework specific ones like this:

import { initTestHelpers } from 'next-page-tester/jest'

☝️ in there we could call jest.resetModules() which wipes the cache.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Amplify JavaScript adds server-side rendering (SSR) support ...
When using Amplify JavaScript to build web applications, you can now incorporate server-side rendering (SSR) with frameworks like Next.js and ...
Read more >
Hosting Nuxt.js SSR on Amplify AWS - Kodius
You can host Nuxt SSR universal app on Amplify in a few clicks and have it hosted hassle free and almost free as...
Read more >
Nuxt.js Server Side Rendering (SSR) support #1860 - GitHub
Run NITRO_PRESET=aws-lambda yarn build to generate a Lambda compatible version · Zip content of your . · Create a new Lambda function (manually ......
Read more >
Hosting - Nuxt.js - JavaScript - AWS Amplify Docs
To use Amplify Hosting, visit the Amplify Console and click GET STARTED under Deploy. ... In the App build and test settings view,...
Read more >
Going Serverless with Nuxt (Composition API) + AWS Amplify ...
In this article we will be learning how we can integrate AWS Amplify with-in a Nuxt app. We will be going over from...
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