Questions tagged [node-fetch]

462 questions
5
votes
1 answer

FetchError: invalid json response body

I'm using node-fetch to send some json data to an IFTTT restpoint. The data is successfully sent to the endpoint, but I'm getting an error in my NodeJS console. As you can see, it returns undefined then says there was an invalid json response body.…
user126440
  • 391
  • 1
  • 2
  • 19
5
votes
2 answers

Fetch with absolute url prefix

Most of the times I prefix fetch or node-fetch with an http://localhost (to make it an absolute url). import fetch from 'node-fetch'; fetch('http://localhost/whatever') Is there any way of avoiding the localhost part, other than simply placing…
zurfyx
  • 31,043
  • 20
  • 111
  • 145
4
votes
3 answers

How to use node-fetch with Jest and Typescript?

I'm trying to setup a very simple NPM codebase that I can use to drive an API to do some testing. The line of code causing the error is just import fetch from "node-fetch";, see the code. For the setup/configuration, I'm following this repository…
Shorn
  • 19,077
  • 15
  • 90
  • 168
4
votes
2 answers

testing with mocha + node-fetch + typescript gives strange error

I adapted a project to use Mocha, and I ran into a bizarre error that took me a while to diagnose. > npm run test TypeError: Unknown file extension ".ts" for C:\code\mocha-example\packages\typescript\test\index.spec.ts` ... stack ... at…
4
votes
1 answer

Typescript error when using require - This expression is not callable. Type 'typeof import(...)' has no call signatures.ts(2349)

I'm trying to run this script const fetch = require('node-fetch'); function test() { fetch('https://google.com') .then(res => res.text()) .then(text => console.log(text)) } test(); But i get this error This expression is not…
Oba Api
  • 231
  • 1
  • 3
  • 10
4
votes
1 answer

Prevent memory/connection leaks when piping fetched response to client

Context: I have some code that looks roughly like this: const express = require("express"); const app = express(); const fetch = require('node-fetch'); app.get("/file/:path", async function(request, response) { const path = request.params.path; …
joe
  • 3,752
  • 1
  • 32
  • 41
4
votes
1 answer

How to get basic Shopify GraphQL Admin API working with nodeJS?

I had a very frustrating evening yesterday, trying to get the basic Shopify GraphQL Admin API example working with nodeJS. The original Shopify example code is here. The problem is that my code returns a status 400 - Bad Request. I have enabled a…
DanJHill
  • 167
  • 2
  • 12
4
votes
2 answers

Authentication POST works in 'request' but not with 'node-fetch'

I've written an authentication request that works with the request module but fails to return the desired 'authentication token' cookie with the node-fetch module that I'm trying to move towards since 'request' has been deprecated. Here is the…
garson
  • 1,505
  • 3
  • 22
  • 56
4
votes
1 answer

React fetch() cache expiration after 5 minutes

Could anyone share some guidance into how to cache a call in the browser and have it last 5 minutes, 30 seconds, really anytime at all? I'm having some real difficulties with this. This works but can't figure out how to make it expire fetch( …
bryan
  • 8,879
  • 18
  • 83
  • 166
4
votes
2 answers

Duplicate identifier fetch in typescript

Just starting out with Typescript. Made a simple project with a single index.ts file which i want to utilize node-fetch. So my code looks like index.ts var fetch = require('node-fetch'); fetch("https://www.google.com") When running tsc index.ts i…
Return-1
  • 2,329
  • 3
  • 21
  • 56
4
votes
0 answers

Puppeteer - POST request using form-data and node-fetch

I'm trying to make a POST request to upload a binary to a server and the form data is not being sent correctly (or at all). My current integration of node-fetch with puppeteer works fine for POST or GET requests with {"Content-Type":…
Alejandro Cotilla
  • 2,501
  • 1
  • 20
  • 35
3
votes
0 answers

Webpack configuration with node-fetch is giving "node:buffer" is not handled by plugins

I am trying to implement node-fetch with a react app and Webpack setup. But on using the node-fetch. I am getting tons of errors. ERROR in node:buffer Module build failed: UnhandledSchemeError: Reading from "node:buffer" is not handled by…
Nagesh Katna
  • 679
  • 2
  • 7
  • 27
3
votes
2 answers

Differences between Node standard https and node-fetch when providing a certificate

ADP's REST API requires that a SSL certificate and private key be sent with every request. When I use the 'standard, Node.js HTTP(S) module: require('dotenv').config() const fs = require('fs') const path = require('path') const certificate_path =…
craig
  • 25,664
  • 27
  • 119
  • 205
3
votes
2 answers

Why Jest failing on node-fetch giving syntax error on import

I'm trying to understand how to fix the following error using Jest in my unit tests in NodeJS. The test run with this command "test": "NODE_ENV=test jest spec/* -i --coverage --passWithNoTests", I'm also using babel and this is my config { …
Jakub
  • 2,367
  • 6
  • 31
  • 82
3
votes
1 answer

Typescript node-fetch import throws 'SyntaxError: Cannot use import statement outside a module'

As title says, I'm in trouble with the creation of a typescript library npm package. My issue come when trying to import node-fetch to perform fetch calls. I've created this sample git repo that reproduce my problem. I've used those command to come…
Daniele Tentoni
  • 178
  • 1
  • 13