aws-api-gateway-cli-test icon indicating copy to clipboard operation
aws-api-gateway-cli-test copied to clipboard

ReferenceError: fetch is not defined

Open ghost opened this issue 7 years ago • 5 comments

I'm following the tutorial at: https://serverless-stack.com/chapters/test-the-apis.html

I'm using node v8.9.4 and the latest packages as of 2/12/2018

I get this error:

apig-test --username [email protected] --password Passw0rd! --user-pool-id us-west-2_xZGqbyKso --app-client-id 4v4l8u687ku8b83lr9cd5irog6 --cognito-region us-west-2 --identity-pool-id us-east-1:b9f7dd39-1216-48bd-8580-132ca7fad875 --invoke-url https://hw9qpley70.execute-api.us-west-2.amazonaws.com/prod --api-gateway-region us-west-2 --path-template /notes --method POST --body "{\"content\":\"hello world\",\"attachment\":\"hello.jpg\"}"
Authenticating with User Pool
C:\Users\Paul\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\amazon-cognito-identity-js\lib\Client.js:54
    fetch(this.endpoint, options).then(function (resp) {
    ^

ReferenceError: fetch is not defined
    at Client.request (C:\Users\Paul\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\amazon-cognito-identity-js\lib\Client.js:54:5)
    at C:\Users\Paul\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\amazon-cognito-identity-js\lib\CognitoUser.js:316:21
    at AuthenticationHelper.getLargeAValue (C:\Users\Paul\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\amazon-cognito-identity-js\lib\AuthenticationHelper.js:85:7)
    at CognitoUser.authenticateUserDefaultAuth (C:\Users\Paul\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\amazon-cognito-identity-js\lib\CognitoUser.js:294:26)
    at CognitoUser.authenticateUser (C:\Users\Paul\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\amazon-cognito-identity-js\lib\CognitoUser.js:257:19)
    at authenticate (C:\Users\Paul\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\index.js:106:15)
    at Object.<anonymous> (C:\Users\Paul\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\index.js:198:1)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)

ghost avatar Feb 12 '18 23:02 ghost

@paul-tx This seems like an issue with the Cognito JS SDK. Can I see your package.json?

jayair avatar Feb 17 '18 00:02 jayair

Hi Jay, I’m not sure which project I was doing this for. One thing I know though is that I’m fastidious about always using the latest version of packages.

From: Jay V Sent: Friday, February 16, 2018 4:06 PM To: AnomalyInnovations/aws-api-gateway-cli-test Cc: paul-tx; Mention Subject: Re: [AnomalyInnovations/aws-api-gateway-cli-test] ReferenceError:fetch is not defined (#7)

@paul-tx This seems like an issue with the Cognito JS SDK. Can I see your package.json? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.


This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

ghost avatar Feb 17 '18 14:02 ghost

I encountered a similar issue in another script I was building using amazon-cognito-identity-js library v2.0.0 on node v6.10.3 I was able to fix it by adding node-fetch npm to the project and setting a global for it. global.fetch = require('node-fetch');

sw-waterford avatar Feb 17 '18 21:02 sw-waterford

@sw-waterford Did you add this to the index.js https://github.com/AnomalyInnovations/aws-api-gateway-cli-test/blob/master/index.js?

jayair avatar Feb 18 '18 22:02 jayair

This was in a different project/library if it was added to the index of this project it should be a suitable replacement for the WindowMock library. I have not encountered the issue with this module so I have not tried swapping them out.

sw-waterford avatar Feb 19 '18 06:02 sw-waterford