microbundle icon indicating copy to clipboard operation
microbundle copied to clipboard

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

Open qjnz opened this issue 4 years ago • 3 comments

Hi guys,

I have run into some really weird situation here. Here is some demo code here, which does not use microbundle in that project.

What I am trying to do is like the following:

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

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'.

qjnz avatar Jan 07 '21 03:01 qjnz

I think this may be a regression caused by our recent upgrade of @rollup/plugin-commonjs.

developit avatar Jan 15 '21 16:01 developit

@developit Is there more info that I can provide you?

qjnz avatar Jan 29 '21 04:01 qjnz

@qjnz no other info really, just myself or someone else needs to figure out which requireReturnsDefault and esmExternals values we should be passing to @rollup/plugin-commonjs, since the values we're passing now seem to be broken:

https://github.com/developit/microbundle/blob/d87a5dc286a1edba92ca3ec5b534807688c90854/src/index.js#L470-L471

developit avatar Feb 02 '21 20:02 developit