aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.45k stars 2.13k forks source link

1.2.3 version is incompatible with Server Side Rendering using Next.js #4268

Closed hello2all closed 5 years ago

hello2all commented 5 years ago

Describe the bug 1.2.3 update causes incompatibility issues with Next.js.

Error output: ReferenceError: window is not defined

To Reproduce Steps to reproduce the behavior:

  1. Create a new Next.js project

    npm install -g create-next-app
    create-next-app new
    cd new
  2. Install aws-amplify npm install aws-amplify

  3. Import amplify in the newly created project add import Amplify from 'aws-amplify' into /pages/index.js.

  4. Start dev server npm run dev

Expected behavior aws-amplify should be SSR compatible.

Screenshots a complete dump of the error output is provided below:

$ npm run dev

> create-next-example-app@ dev /Users/Ted/Desktop/test/new
> next

[ wait ]  starting the development server ...
[ info ]  waiting on http://localhost:3000 ...
The static directory has been deprecated in favor of the public directory. https://err.sh/zeit/next.js/static-dir-deprecated
[ ready ] compiled successfully - ready on http://localhost:3000
[ wait ]  compiling ...
[ event ] client pings, but there's no entry for page: /
[ ready ] compiled successfully - ready on http://localhost:3000
[ event ] build page: /
[ wait ]  compiling ...
[ ready ] compiled successfully - ready on http://localhost:3000
ReferenceError: window is not defined
    at Object.<anonymous> (/Users/Ted/Desktop/test/new/node_modules/aws-amplify/dist/aws-amplify.js:10:4)
    at Module._compile (module.js:662:30)
    at Object.Module._extensions..js (module.js:673:10)
    at Module.load (module.js:575:32)
    at tryModuleLoad (module.js:515:12)
    at Function.Module._load (module.js:507:3)
    at Module.require (module.js:606:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/Ted/Desktop/test/new/node_modules/aws-amplify/index.js:6:19)
    at Module._compile (module.js:662:30)
    at Object.Module._extensions..js (module.js:673:10)
    at Module.load (module.js:575:32)
    at tryModuleLoad (module.js:515:12)
    at Function.Module._load (module.js:507:3)
    at Module.require (module.js:606:17)
    at require (internal/module.js:11:18)
[ event ] build page: /next/dist/pages/_error

Desktop (please complete the following information):

Amplify context

Additional context N.A.

Sample code N.A.

anarerdene commented 5 years ago

+1

Amplifiyer commented 5 years ago

This is same as #4243 and has been fixed in unstable release. We will release it soon.

Amplifiyer commented 5 years ago

@anarerdene, can you confirm in your node_modules directory, what version of aws-amplify you are using, stable 1.2.3 or 1.2.4-unstable.5

anarerdene commented 5 years ago

hi @Amplifiyer ,

im using stable 1.2.3 and 1.2.4-unstable.5. But still window not working error.

sammartinez commented 5 years ago

@hello2all @anarerdene We did do a release yesterday, version 1.2.4 and the Pull request that I referenced resolves this issue. I do want to state that Amplify doesn't officially support SSR at this time. Please add a reaction or a +1 for SSR as this is an open feature request for that. I am going to resolve this issue, please feel free to reopen this issue if were are still experiencing this after installing the latest version released.

samstr commented 4 years ago

Amplify needs SSR. I've been trying to deploy a NextJS app to Amplify and I will probably have to abandon this idea soon enough if it's an impossible concept

Amplifiyer commented 4 years ago

@samstr, what issues are you facing while deploying the NextJS app? Can you create another issue with a detailed repro steps?

rickysychan commented 4 years ago

@Amplifiyer I've tried to do the same, the deploy is successful but when I got to the app it says there is an error and I've been redirected too many times.

Here are my build deets

version: 0.1 frontend: phases: preBuild: commands:

npm run build runs "next build"

sebsto commented 4 years ago

See https://github.com/aws-amplify/amplify-js/issues/4268

github-actions[bot] commented 3 years ago

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.