Referenceerror: Fetch Is Not Defined

JS - ReferenceError: fetch is not defined

You're running it on Node JS instance in Paiza.io. Use CodeSandbox or CodePen for running your code please. And here... Paiza runs on Node JS not on Browser.

In your example, you need to use fetch() this way:

fetch(
"https://sochain.com/api/v2/address/LTC/LMSuo8W7CiXs8oFs1sJh77AQ54tCZM42Ay"
)
.then((res) => res.json())
.then((obj) => document.write(obj["data"]["received_value"]));

ReferenceError: fetch is not defined - Postman

Does Postman not implement the Fetch API?

I think not. The closest correspondence to the fetch() command
is pm.sendRequest().

But pm.sendRequest returns a pm object and not a Promise,
at least for now.

I have found a workaround, though.
In the code snippet below I define the pmFetch() function which is meant to
do what the fetch() command does in a normal web browser.

pmFetch('https://jsonplaceholder.typicode.com/todos/3')
.then(response => response.json())
.then(responseBody => {
console.log('The response body:');
console.log(responseBody);
console.log('responseBody.title: "' + responseBody.title + '"');
});
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
function pmFetch (url) {
return new Promise ((resolve, reject) => {
pm.sendRequest(url, function (err, response) {
if (err) reject(err);
resolve(response);
});
});
}

pmFetch mimics the Fetch API

Here is a link to the Postman Collection
in case you want to download, import, and run the collection.

Reference:

  • How to make pm.sendRequest return a Promise

D3.CSV ReferenceError: fetch is not defined

the following should work for you.

source

You need an environment that supports the Fetch API, such as a a web browser. Node does not currently support Fetch, though it may in the future. If you want to load this library in an environment that does not natively support Fetch you will need to load your own polyfill such as node-fetch.



Related Topics



Leave a reply



Submit