developit / developit/microbundle

Why re-export overriding does not work if I use microbundle ?

Open
#782 3 comments 0 reactions 0 assignees View on GitHub
bug :bug: help wanted :wave: upstream
Dominant language
JavaScript
Stars
8.1k
Forks
358
PR merge metrics
No merged PRs in 30d

Description

Hi guys,

I have run into some really weird situation here. Here is some [demo code](https://github.com/qjnz/re-export-override-demo) here, which does not use `microbundle` in that project.

What I am trying to do is like the following:
```js
import { theFunction } from './myOverrides'

export * from 'some-library'
export { theFunction } // theFunction here should override the theFunction from the `some-library`
```

However, from the emitted umd.js or common.js file that I got from `microbundle`, the `theFunction` does not get override since I can see that the legacy javascript code I got from the output is doing something like below

```js
Object.keys(r).forEach(function (e) {
'default' !== e &&
Object.defineProperty(exports, e, {
enumerable: !0,
get: function () {
return r[e]
},
})
}),
```

which the latter export `export { theFunction }` does not override it.

My question is that if somehow the `microbundle` does some magic here about `export * from 'some-library'`.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the linked re-export-override-demo, then run its microbundle build and inspect the emitted UMD and CommonJS files around the Object.keys(r) export handling. Compare the generated behavior with the shown export order and determine whether the override is expected to work. Done means the behavior is explained and either corrected or clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.