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 callable. Type 'typeof import("(...)/node_modules/node-fetch/@types/index")' has no call signatures.ts(2349)
although it works when i use import
import fetch from 'node-fetch';
why and how to fix it?
As per spender's comment, you can change the require to use this destructuring:
const {default : fetch} = require('node-fetch');
This has worked for me in a similar situation (using axios in node, which has a similar API)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With