developit / microbundle

📦 Zero-configuration bundler for tiny modules.
https://npm.im/microbundle
MIT License
8.06k stars 361 forks source link

Broken build due to mangled dependency props #819

Open make-github-pseudonymous-again opened 3 years ago

make-github-pseudonymous-again commented 3 years ago

I have some code that imports a named export of a dependency as follows:

import { _fn } from '@x/y';
...
_fn(...); // calling _fn

With mangle configured with "regex": "^_[^_]", the default build (index.js) transpiles this to:

const z = require('@x/y');
...
z.a(...); // calling _fn???

Disabling mangling works as expected:

const z = require('@x/y');
...
z._fn(...); // calling _fn

There is a similar problem with the umd build.

Any way around this?

wardpeet commented 3 years ago

Hi @aureooms!

Sorry to hear you're running into an issue. To help us best begin debugging the underlying cause, it is incredibly helpful if you're able to create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it.

If you're up for it, we'd very much appreciate if you could provide a minimal reproduction and we'll be able to take another look.

Thanks for trying out microbundle

make-github-pseudonymous-again commented 3 years ago

I cannot promise to find time to produce a minimal failing example. Currently, I workaround the problem by either disabling mangling, or marking all named imports that match the regex as reserved.

make-github-pseudonymous-again commented 3 years ago

For the UMD build it's worse: since exports are created with function(exports) { ... ; exports._fn = x; } even internal exports names that match the regex get mangled, in addition to the external import names. I guess you have to be really picky with what you want to mangle for it to be useful.