AnomalyInnovations / aws-api-gateway-cli-test

A simple CLI to test API Gateway endpoints with IAM authorization
MIT License
120 stars 29 forks source link

ReferenceError: fetch is not defined #7

Open ghost opened 6 years ago

ghost commented 6 years ago

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 admin@example.com --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)
jayair commented 6 years ago

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

ghost commented 6 years ago

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

sw-waterford commented 6 years ago

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');

jayair commented 6 years ago

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

sw-waterford commented 6 years ago

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.