dabit3 / gatsby-auth-starter-aws-amplify

Starter Project with Authentication with Gatsby & AWS Amplify
MIT License
324 stars 399 forks source link

SSR part of gatsby build fails due to AWS Amplify client libraries not being "Node safe" #26

Open ecomonestop opened 4 years ago

ecomonestop commented 4 years ago

When I run npm run build, I get the following error: failed Building static HTML for pages - 8.576s

ERROR #95312

"navigator" is not available during server side rendering.

See our docs page for more info on this error: https://gatsby.dev/debug-html

85 | var ACCEPTED_CODES = [202]; 86 | var MOBILE_SERVICE_NAME = 'mobiletargeting';

87 | var BEACON_SUPPORTED = navigator && typeof navigator.sendBeacon === 'function'; | ^ 88 | // events buffer 89 | var BUFFER_SIZE = 1000; 90 | var FLUSH_SIZE = 100;

WebpackError: ReferenceError: navigator is not defined

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! gatsby-auth-starter-aws@1.0.0 build: gatsby build npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the gatsby-auth-starter-aws@1.0.0 build script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\romer\AppData\Roaming\npm-cache_logs\2019-12-10T13_36_16_975Z-debug.log

Can Aws Amplify client libraries be "Node safe" to prevent this issue?

goldhand commented 4 years ago

The issue is that this package uses an old version of aws-amplify, specifically this line in @aws-amplify/analytics is causing this error.

Fixing this required replacing the old version of aws-amplify.

yarn add aws-amplify@2.2.0

Which checks to see that navigator is not undefined before accessing the object property see this commit