Open jacob-ebey opened 1 year ago
oh i think i know why this happens
I can reproduce this as well! Been having lots of issues in my repo because of it and having to do a lot of weird workarounds.
Doesn't seem to happen when you enable minification
Enabling minification seems to cause issues with JSX runtime imports not being added. Once this is fixed I'll explore getting a reproduction of the JSX issue well.
Doesn't seem to happen when you enable minification
That's a workaround
I have a hunch as to why minifying it solves the issue. I got the following output when compiling my own test case, with the files ./dependency.ts and ./main.ts, with the --minify-identifiers
flag set:
function o() {
console.log("foobar");
}
export {
o as foobar
};
export { o as a };
To contrast, when I compile the dependency.ts file standalone, lines 7,8 are removed.
function o() {
console.log("foobar");
}
export {
o as foobar
};
When compiling a file and its dependency under the --minify-identifiers
flag, it seems the bundler exports each symbol with its regular name and a minified one. Presumably, this is done to alllow the end user to import each symbols under either the original or shortened name.
I just hit this too. bun build --splitting client/ajax.ts --outdir static
works fine, but if I do bun build --splitting client/*.ts --outdir static
, that same file ends with
export {
postJson,
post,
okFetch,
baseFetch
};
export { ContentTypes, REDIRECT_CODE, postJson };
Note how postJson
is exported twice now.
I see, because one of the other files also wants to import postJson
, so it exports one with an unmangled name so the browser can import it, and then a mangled name so that the other file can import it. You can see this when --minify
is enabled:
export {c as postJson, Y as post, K as okFetch, U as baseFetch};
export {v as a, Z as b, c};
The first set of exports is for the browser, the 2nd is for the other scripts.
Any update on this?
Bump for visibility
Any updates? Also occurring in recent version, related issue #10631
I just ran into this issue as well, confirm still happening as of bun 1.1.21
Still there in 1.1.37 and blocking for bun adoption in our company's projects
What version of Bun is running?
1.0.1
What platform is your computer?
Darwin 22.5.0 arm64 arm
What steps can reproduce the bug?
Double exports seems to arise when one entrypoint is re-exporting from another entrypoint.
A reproduction can be found here: https://github.com/jacob-ebey/bun-bug-reproductions/tree/main/bugs/bundler-double-exports
What is the expected behavior?
Entrypoint output is a valid ES module.
What do you see instead?
Duplicate exports in the
dist/entry-b.js
that ends up looking something like:Additional information
I'm going to be using https://github.com/jacob-ebey/bun-bug-reproductions/ as a general bug-reproduction location for anything else I run across.