Skip to content

TypeError: when using fetch in Node but not in Bun #58508

@kevgeoleo

Description

@kevgeoleo

Version

24.1.0

Platform

Microsoft Windows NT 10.0.26100.0 x64

Subsystem

No response

What steps will reproduce the bug?

Hi,

I encountered an error while running the following code snippet in NodeJs but not in Bun:

Object.prototype.__defineGetter__(0, function () {
  throw 42;
});

const url = "https://example.com";
try {
  const response = await fetch(url);
} catch (error) {
  console.error("Error:", error);
}

The Error:

Error: TypeError: Cannot set property 0 of #<Object> which has only a getter
    at Array.push (<anonymous>)
    at lib/llhttp/constants.js (node:internal/deps/undici/undici:3274:22)
    at __require (node:internal/deps/undici/undici:6:50)
    at lib/dispatcher/client-h1.js (node:internal/deps/undici/undici:6327:21)
    at __require (node:internal/deps/undici/undici:6:50)
    at lib/dispatcher/client.js (node:internal/deps/undici/undici:8118:21)
    at __require (node:internal/deps/undici/undici:6:50)
    at lib/dispatcher/pool.js (node:internal/deps/undici/undici:8567:18)
    at __require (node:internal/deps/undici/undici:6:50)
    at lib/dispatcher/agent.js (node:internal/deps/undici/undici:8657:16)
node:internal/async_hooks:541
  execution_async_resources[offset] = resource;
                                    ^

TypeError: Cannot set property 0 of #<Object> which has only a getter
    at pushAsyncContext (node:internal/async_hooks:541:37)
    at emitBeforeScript (node:internal/async_hooks:510:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:80:7)

How often does it reproduce? Is there a required condition?

There is no specific condition

What is the expected behavior? Why is that the expected behavior?

No output

What do you see instead?

Error: TypeError: Cannot set property 0 of #<Object> which has only a getter
    at Array.push (<anonymous>)
    at lib/llhttp/constants.js (node:internal/deps/undici/undici:3274:22)
    at __require (node:internal/deps/undici/undici:6:50)
    at lib/dispatcher/client-h1.js (node:internal/deps/undici/undici:6327:21)
    at __require (node:internal/deps/undici/undici:6:50)
    at lib/dispatcher/client.js (node:internal/deps/undici/undici:8118:21)
    at __require (node:internal/deps/undici/undici:6:50)
    at lib/dispatcher/pool.js (node:internal/deps/undici/undici:8567:18)
    at __require (node:internal/deps/undici/undici:6:50)
    at lib/dispatcher/agent.js (node:internal/deps/undici/undici:8657:16)
node:internal/async_hooks:541
  execution_async_resources[offset] = resource;
                                    ^

TypeError: Cannot set property 0 of #<Object> which has only a getter
    at pushAsyncContext (node:internal/async_hooks:541:37)
    at emitBeforeScript (node:internal/async_hooks:510:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:80:7)

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidIssues and PRs that are invalid.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions