Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removal of Polyfill leads to window is not defined error in React web app with SSR #1770

Closed
dhanesh-kapadiya opened this issue Sep 27, 2018 · 13 comments
Labels
SSR Issues related to Server Side Rendering

Comments

@dhanesh-kapadiya
Copy link

dhanesh-kapadiya commented Sep 27, 2018

After this update
core@1.0.13-unstable.1

We are getting window is not defined error.
Error points to ../../src/RNComponents/index.ts

we are using custom aws config setup.
we have set Amplify.configure(awsConfig) in redux provider wrapper file which executes amplify configure function outside of react component, I have also tried to call the Amplify.configure in componentDidMount function but still getting same error.

In older version of our project,
we were using core@1.0.9, and it is working perfectly.

This is how our project setup is,
This Provider.js component is imported inside all the pages to check user authentication.

provider.js

import React, { Component } from 'react'
import { Provider } from 'react-redux'
import store from '../store'
import { Auth } from 'aws-amplify'
import '../../awsConfig.js'

export default class ProviderWithAuth extends Component {
  ...
}

awsConfig.js

import Amplify from 'aws-amplify';
import { default as config } from '../../config'

Amplify.configure({ config })

If we are doing something wrong, please guide us to make correction in our project by providing best practice for the usage of Amplify.configure function.

@dbrookes
Copy link

I have the same issue, this change has broken server side rendering because window.localStorage does not exist.

@dhanesh-kapadiya dhanesh-kapadiya changed the title Removal of Polyfill leads to window is not defined error in React web app Removal of Polyfill leads to window is not defined error in React web app with SSR Sep 28, 2018
@romainquellec
Copy link

I have the same issue. And window is poluted, so style-jsx think its client side and goes wild.

@rhernand3z
Copy link

Same issue here, it was working fine previously, I am using SSR as well and invoke the Amplify methods on componentDidMount() with the same error.

@haverchuck haverchuck added the SSR Issues related to Server Side Rendering label Oct 2, 2018
@haverchuck
Copy link
Member

Related to #1811

@dhanesh-kapadiya
Copy link
Author

dhanesh-kapadiya commented Oct 2, 2018

@haverchuck
I'm using core@1.0.9 build which is safe. and it has polyfill for window object.
It was removed in core@1.0.13-unstable.1 update

I have tried using it inside componentDidMount, but still throws error.
Do you recommend us to use window and node-fetch polyfill ?
For me, I dont need polyfills for my projects, My thought is to keep those polyfills in aws-amplify@core module, which should support all types of rendering (client and server side) because it will be the most common place for all the users to have such fix. that's just my thought.

Let us know what you would recommend. Cheers! 🥂

@dbrookes
Copy link

dbrookes commented Oct 2, 2018

This seems to be fixed in the latest unstable via https://github.com/aws-amplify/amplify-js/pull/1802/files

@haverchuck
Copy link
Member

@dhanesh-kapadiya - Does this error surface when you use the unstable build (using the @unstable tag on an npm install)?

@dhanesh-kapadiya
Copy link
Author

No, I only used stable version, which installed core@1.0.13-unstable.1 through yarn, that update have this error, after that I couldn't get a chance to test new releases again. I'll update my project with the latest unstable build of amplify and I'll update you on this issue as soon as I can. Thanks man.🥂

@rhernand3z
Copy link

I was able to resolve the issue by installing the @unstable build. My setup uses Node SSR React/Redux. I was able to transpile my server side ES6 code via Webpack 4 without issues.

"aws-amplify": "1.1.6-unstable.2"

@haverchuck -- Will this be rolled out to a stable version soon?

@dhanesh-kapadiya
Copy link
Author

@haverchuck I have tested the unstable build in my project and it seems to be working. And I've checked latest stable build as well, that seems to be working too.

@mlabieniec
Copy link
Contributor

Great! Let us know if you need to reopen this.

@romainquellec
Copy link

Wait, it's working with "1.1.6-unstable.2" but it does not with "1.1.9".
Is there any explanation somewhere about your differents branches ?

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
SSR Issues related to Server Side Rendering
Projects
None yet
Development

No branches or pull requests

6 participants