Usage with @aws-amplify next/SSR
See original GitHub issueHi 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:
- Created 3 years ago
- Comments:6
Top 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 >
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 Free
Top 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

A fix is available in #73 which is blocked until Jest v27 gets released.
I looked into this and its caused by a very annoying issue we are facing in this library: external modules eagerly evaluating
document|windowexistence on top level (on import). This happens beforenext-page-testeris in “control” of things and could “wire” it correctly.@toomuchdesign:
@aws-amplifyfirst checks if its browser environment upon import and that evaluates totruebecause of JSDOM, and then tries to accesslocalStorageingetServerSidePropswhich 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
windowanddocumentin ourinitTestHelpersand then restoring them ingetPagewhich would help in this example, but will break other libraries, e.g.react-hook-formwhich 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
testframeworks are using hacks to “re-implement” require mechanism.If there is not a reliable cross-framework way we could consider implementing
frameworkspecific ones like this:☝️ in there we could call
jest.resetModules()which wipes the cache.