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

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

Open
ecomonestop opened this issue Dec 10, 2019 · 1 comment

Comments

@ecomonestop
Copy link

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

  • AWSPinpointProvider.js:87 Module../node_modules/@aws-amplify/analytics/lib-esm/Providers/AWSPinpointProvider.js
    node_modules/@aws-amplify/analytics/lib-esm/Providers/AWSPinpointProvider.js:87:1

  • Analytics.js:1 Module../node_modules/@aws-amplify/analytics/lib-esm/Analytics.js
    node_modules/@aws-amplify/analytics/lib-esm/Analytics.js:1:1

  • index.js:1 Module../node_modules/@aws-amplify/analytics/lib-esm/index.js
    node_modules/@aws-amplify/analytics/lib-esm/index.js:1:1

  • index.js:1 Module../node_modules/aws-amplify/lib-esm/index.js
    node_modules/aws-amplify/lib-esm/index.js:1:1

  • header.js:1 Module../src/components/header.js
    src/components/header.js:1:1

  • 404.js:1 Module../src/pages/404.js
    src/pages/404.js:1:1

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: gatsby build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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
Copy link

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.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants