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.41k stars 2.11k forks source link

navigator is not defined error #754

Closed praveshkhatana closed 6 years ago

praveshkhatana commented 6 years ago

I am trying to integrate it with latest Nativescript-angular and using "[nativescript-nodeify](https://github.com/EddyVerbruggen/nativescript-nodeify)**" plugin.

require("nativescript-nodeify");
var Amplify = require("aws-amplify");
Amplify.configure({
    Auth: {
    // REQUIRED - Amazon Cognito Identity Pool ID
        identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab', 
    // REQUIRED - Amazon Cognito Region
        region: 'XX-XXXX-X', 
    // OPTIONAL - Amazon Cognito User Pool ID
        userPoolId: 'XX-XXXX-X_abcd1234',
    // OPTIONAL - Amazon Cognito Web Client ID
        userPoolWebClientId: 'XX-XXXX-X_abcd1234', 
    }
});

but getting this error when I try to call "Amplify.configure"

JS: ERROR Error: Uncaught (in promise): ReferenceError: navigator is not defined
JS: ReferenceError: navigator is not defined
JS:     at standardBrowserEnv (file:///data/data/org.nativescript.awsamplify/files/app/tns_modules/axios/lib/helpers/isURLSameOrigin.js:11:39)
JS:     at Object.<anonymous> (file:///data/data/org.nativescript.awsamplify/files/app/tns_modules/axios/lib/helpers/isURLSameOrigin.js:60:5)
JS:     at require (<anonymous>:1:266)
JS:     at Object.<anonymous> (file:///data/data/org.nativescript.awsamplify/files/app/tns_modules/axios/lib/adapters/xhr.js:7:23)
JS:     at require (<anonymous>:1:266)
JS:     at getDefaultAdapter (file:///data/data/org.nativescript.awsamplify/files/app/tns_modules/axios/lib/defaults.js:20:15)
JS:     at Object.<anonymous> (file:///data/data/org.nativescript.awsamplify/files/app/tns_modules/axios/lib/defaults.js:29:12)
JS:     at require (<anonymous>:1:266)
JS:     at Object.<anonymous> (file:///data/data/org.nativescript.awsamplify/files/app/tns_modules/axios/lib/core/Axios.js:3:16)
JS:     at require (<anonymous>:1:266)
JS:     at Object.<anonymous> (file:///data/data/org.nativescript.awsamplify/files/app/tns_modules/axios/lib/axios.js:5:13)
JS:     at require (<anonymous>:1:266)
JS:     at Object.<anonymous> (file:///data/data/org.nativescript.awsamplify/files/app/tns_modules/axios/index.js:1:78)
JS:     at require (<anonymous>:1:266)
JS:     at Object.<anonymous> (file:///data/data/org.nativescript.awsamplify/files/app/tns_modules/aws-amplify/lib/API/RestClient.js:70:15)

"aws-amplify": "^0.3.3", "nativescript-angular": "~5.3.0", "nativescript-nodeify": "^0.7.0",

praveshkhatana commented 6 years ago

Changed it to "aws-amplify": "^0.2.9" version and everything working fine now :)

Just getting few warning messages

praveshkhatana commented 6 years ago

Why you closed this issue? Latest version "aws-amplify": "^0.3.3" still has an issue.

praveshkhatana commented 6 years ago

@manueliglesias how to fix it

heldr commented 5 years ago

It only uses navigator to retrieve userAgent https://github.com/aws-amplify/amplify-js/blob/master/packages/amazon-cognito-identity-js/src/CognitoUser.js#L828

You can mock it in node:

global.navigator = {
  userAgent: 'NodeJS'
};
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.