question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReferenceError: fetch is not defined

See original GitHub issue

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)

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
sw-waterfordcommented, Feb 19, 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’);

0reactions
sw-waterfordcommented, Feb 19, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReferenceError: fetch is not defined - javascript - Stack Overflow
fetch () was designed for the browser and then back-ported to node.js in a third party module whcih you are apparently missing. The...
Read more >
ReferenceError: fetch is not defined in NodeJs | bobbyhadz
The "ReferenceError: fetch is not defined" occurs when the fetch() method is used in an environment where it's not supported - most commonly...
Read more >
ReferenceError: fetch is not defined in Node.js
In conclusion, the ReferenceError occurs if you are using an older version ( < 18) of Node.js and it can be resolved by...
Read more >
How to fix 'ReferenceError: fetch is not defined' in Node.js
First, let's replicate the issue. You can update the index.js to the following and run node index.js , you should be able to...
Read more >
Fetch is not defined in JavaScript | Dr Vipin Classes - YouTube
Fetch is not defined | ES6 JavaScript | Dr Vipin ClassesAbout this video: In this video, I explained about following topics: 1.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found