Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundler Duplicate Exports #5344

Open
jacob-ebey opened this issue Sep 14, 2023 · 12 comments
Open

Bundler Duplicate Exports #5344

jacob-ebey opened this issue Sep 14, 2023 · 12 comments
Labels
bug Something isn't working

Comments

@jacob-ebey
Copy link

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:

function b() {
}
export {
  b
};

export { b };

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.

@jacob-ebey jacob-ebey added the bug Something isn't working label Sep 14, 2023
@Jarred-Sumner
Copy link
Collaborator

oh i think i know why this happens

@hex2f
Copy link
Contributor

hex2f commented Sep 14, 2023

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.

@hex2f
Copy link
Contributor

hex2f commented Sep 14, 2023

Doesn't seem to happen when you enable minification

@jacob-ebey
Copy link
Author

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.

@raulfdm
Copy link

raulfdm commented Oct 7, 2023

Doesn't seem to happen when you enable minification

That's a workaround

@anabelle2001
Copy link

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.

@mnpenner
Copy link

mnpenner commented Nov 18, 2023

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.

@rdev06
Copy link

rdev06 commented Apr 8, 2024

Any update on this?

tanishqmanuja added a commit to tanishqmanuja/consistent-env that referenced this issue Apr 21, 2024
@eokic
Copy link

eokic commented Jun 28, 2024

Bump for visibility

@vinny-silveira
Copy link

Any updates? Also occurring in recent version, related issue #10631

@dgpt
Copy link

dgpt commented Jul 25, 2024

I just ran into this issue as well, confirm still happening as of bun 1.1.21

@ceymard
Copy link
Contributor

ceymard commented Nov 20, 2024

Still there in 1.1.37 and blocking for bun adoption in our company's projects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests