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
Let me explain with an example.
When bundling
axiosto esModule output with esbuild, the following error occurs when imported:Looks like this comes from the
follow-redirectspackage(which is required byaxios) that has this code:where
nativeProtocolis originallyrequire('http').On the process of bundling, the
require('http')seems to be converted with esbuild's__exportStarfunction to have only getter, which the code is produced with this line:esbuild/internal/runtime/runtime.go
Line 98 in e8a22dc
I'm not sure this should be addressed in esbuild, but
axiosis 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