Skip to content

Cannot set property of #<Object> which has only a getter #587

@Kivol

Description

@Kivol

Let me explain with an example.

When bundling axios to esModule output with esbuild, the following error occurs when imported:

      wrappedProtocol.request = function(input, options, callback) {
                              ^
TypeError: Cannot set property request of #<Object> which has only a getter

Looks like this comes from the follow-redirects package(which is required by axios) that has this code:

var wrappedProtocol = exports[scheme] = Object.create(nativeProtocol);
wrappedProtocol.request = function(input, options, callback) {
...

where nativeProtocol is originally require('http').

On the process of bundling, the require('http') seems to be converted with esbuild's __exportStar function to have only getter, which the code is produced with this line:

__defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable })

I'm not sure this should be addressed in esbuild, but axios is really common library on JS ecosystem and I think there might be helpful if there's any workaround.

You can reproduce this bug with: https://github.com/Kivol/esbuild-export-star-bug-reproduce

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions