Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fetchCookie Is Not A Function

Tags:

node.js

Maybe I becoming blind, but I don't see where I am wrong. I would use commonjs interface of fetch-cookie. According to the documentation, this is possible, indeed. https://github.com/valeriangalliat/fetch-cookie?tab=readme-ov-file#development

So, I tried:

const fetchCookie = require('fetch-cookie')
const tough = require('tough-cookie');
const username = 'x';
const password = 'x';
 
// Create a cookie jar
const cookieJar = new tough.CookieJar();

// Wrap fetch with fetch-cookie and the created cookie jar
const fetchWithCookies = fetchCookie(fetch, cookieJar);

but:

❯ node testfetch.js 
const fetchWithCookies = fetchCookie(fetch, cookieJar);
                         ^


TypeError: fetchCookie is not a function
    at Object.<anonymous> (/home/user/Documents/testfetch.js:15:26)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
like image 667
gdm Avatar asked Nov 23 '25 13:11

gdm


1 Answers

The function you're looking for is exported as default. It's a bit awkward in CommonJS, but you can reference it explicitly:

const fetchCookie = require('fetch-cookie').default;
// Here -----------------------------------^
like image 94
Mureinik Avatar answered Nov 25 '25 10:11

Mureinik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!