Repository navigation
Cannot make a node-fetch request, TypeError: Cannot read property 'Symbol(requestOptions)' of undefined #36364
Description
Activity
I'm having some difficulty reproducing this:
❯ cat index.js
const fetch = require('node-fetch'); (async () => { const response = await fetch('https://api.github.com/users/github'); const json = await response.json(); console.log(json); })();
❯ node index.js &> /dev/null ❯ echo $? 0 ❯ node -v v15.2.0 ❯ uname -a Linux hp 4.15.0-124-generic #127-Ubuntu SMP Fri Nov 6 10:54:24 UTC 2020 i686 i686 i686 GNU/Linux
As you can see, it exits with a zero error code.
I tracked down the issue and found out that one of the libs in the project, was defining methods on Object and Array Prototype.
When I removed it, it all started to work,
I wonder, what has changed after node v.12.18, that does not allow defining methods on Object/Array prototype??- addedhttpIssues and PRs related to the http subsystem.Issues and PRs related to the http subsystem.
on Dec 6, 2020 - added a commit that references this issue
on Dec 7, 2020 I tracked down the issue and found out that one of the libs in the project, was defining methods on Object and Array Prototype.
When I removed it, it all started to work,
I wonder, what has changed after node v.12.18, that does not allow defining methods on Object/Array prototype??This may be due to expanded use of what we call
primordialson the project. The idea is that if a user changes theObjectprototype, it should affect their code but not Node.js internal code. This is a security precaution but it may cause difficulty for people who "monkey-patch" Node.js internals like AMP vendors. I'd be curious to know what library is exhibiting this problem so we can track down whether this is expected breakage or a bug in Node.js that we need to fix.I tracked down the issue and found out that one of the libs in the project, was defining methods on Object and Array Prototype.
When I removed it, it all started to work,
I wonder, what has changed after node v.12.18, that does not allow defining methods on Object/Array prototype??This may be due to expanded use of what we call
primordialson the project. The idea is that if a user changes theObjectprototype, it should affect their code but not Node.js internal code. This is a security precaution but it may cause difficulty for people who "monkey-patch" Node.js internals like AMP vendors. I'd be curious to know what library is exhibiting this problem so we can track down whether this is expected breakage or a bug in Node.js that we need to fix.Though it looks like @targos has already self-assigned this so they probably have a good idea what the bug is and what the fix is.
Reacted by MehdiTo explain the bug: there was a semver-minor change that introduced a
for ... inloop on therequestsproperty of httpAgent.
If enumerable properties were added toObject.prototype, they would be iterated by this loop, triggering this bug because they probably wouldn't have an object at index0.Reacted by MehdiReacted by Mehdi- added a commit that references this issue
on Dec 13, 2020 - added a commit that references this issue
on Feb 8, 2021 - added 2 commits that reference this issue
on Feb 8, 2021 - added a commit that references this issue
on May 22, 2026
What steps will reproduce the bug?
Any call to foreign api, using a trusted library like "node-fetch", creates error and crash servers, on versions higher than 12.18
Here is the error:
How often does it reproduce? Is there a required condition?
All the time, not in version 12.18 or lower
What is the expected behavior?
a normal fetch, returning the result from any api, mostly a json
What do you see instead?
app crashes!
Additional information