New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fetch ^4.0.0-beta.1 generating error: TypeError [ERR_INVALID_ARG_TYPE]: The listener argument must be of type function. Received an instance of Object #1620
Comments
I just had this issue with node-fetch@3.2.10 when trying to use a Downgraded to 2.6.7 and now it works 🎉 |
@asbjornenge appreciate you responding to my post. I actually was using version 2.6.7 as well, but I have to eventually upgrade to 4.x or at least 3.x due to a vulnerability that was reported recently. Unless they are able to release a 2.x patch. |
I'm also having this issue with version 3.2.9 |
Seems to work when only one parameter is provided to
|
Hi @guillaume-fr , thanks for responding. So what do your imports look like now? Are you saying you had to essentially side step using the feature of node-fetch? |
I just went in Had to do this in place as node-fetch is included as a dependency of another package I'm importing and I just wanted to see if this is easily fixable. Obviously this is not applicable as-is for a production scenario. You would have to find a better way to inject this workaround or wait for an actual fix in this repo. It would be interesting to understand why it fails. It looks like calling with url and options as separated arguments should be allowed. We can avoid the error by providing only one argument but I don't know what's the root cause. |
@fluxquantum94 you can try my PR changing the version in your package.json: |
After upgrading from node-fetch 2.6.7 to "node-fetch": "^4.0.0-beta.1." I am seeing errors with the execution of fetch.
After running node bin/www, I am able to spin up my node backend server but then when making a request I see the following error now:
// Full paths ellided
{"message":"Error fetching tokens: TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received an instance of Object\n at checkListener (node:events:259:3)\n at ClientRequest.once (node:events:661:3)\n at new ClientRequest (node:_http_client:215:10)\n at Object.request (node:https:353:10)\n at /node_modules/agent-base/patch-core.js:25:22\n at file:///node_modules/node-fetch/src/index.js:94:20\n at new Promise ()\n at fetch (file://node_modules/node-fetch/src/index.js:49:9)
Reproduction
const fetch = (...args) =>
import('node-fetch').then(({ default: fetch }) => fetch(...args));
// Variables values ellided
const getTokens = async (code, redirectUrl) => {
const authString =
Basic ${Buffer.from(
${config.Id}:${config.secret}).toString('base64')}
;const fetchTokenURL = tokenUrl +
?code=${code}&grant_type=auth_code&redirect=${redirect}
;try {
let response = await fetch(fetchTokenURL, {
agent: new HttpsProxyAgent(httpProxy),
method: 'POST',
headers: {
Authorization: authString,
Accept: 'application/json',
}
})
let data = await response.json();
return data;
} catch (error) {
logger.info("Error fetching tokens: " + error.stack);
}
}
Steps to reproduce the behavior:
import('node-fetch').then(({ default: fetch }) => fetch(...args));
Expected behavior
I should be able to hit my target endpoint without issues after import problem was resolved.
Screenshots
Your Environment
alpine linux
Additional context
The text was updated successfully, but these errors were encountered: