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

ReferenceError: fetch is not defined #7

Open
ghost opened this issue Feb 12, 2018 · 5 comments
Open

ReferenceError: fetch is not defined #7

ghost opened this issue Feb 12, 2018 · 5 comments

Comments

@ghost
Copy link

ghost commented Feb 12, 2018

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)
@jayair
Copy link
Member

jayair commented Feb 17, 2018

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

@ghost
Copy link
Author

ghost commented Feb 17, 2018 via email

@sw-waterford
Copy link

sw-waterford commented Feb 17, 2018

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
Copy link
Member

jayair commented Feb 18, 2018

@sw-waterford
Copy link

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.

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