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

Duplicate Exports Generated by bun build When Using --splitting Option with Glob Pattern in Entry #14493

Open
ismoiliy98 opened this issue Oct 11, 2024 · 0 comments
Labels
bug Something isn't working bundler Something to do with the bundler confirmed bug We can repo this issue

Comments

@ismoiliy98
Copy link

What version of Bun is running?

1.1.30

What platform is your computer?

Darwin 23.5.0 arm64 arm

What steps can reproduce the bug?

Description

I’ve been considering switching to Bun as an all-in-one tool for my project, and everything has worked smoothly so far. However, I encountered an issue with the output generated by the build command

My project consists of numerous submodules, which need to be built as separate modules. To avoid manually specifying each entry file for every submodule, I used a glob pattern for the entry option of the build command (e.g., src/**/*.ts)

The issue arises when I include the --splitting option in the build command. In this case, all exports in each module are duplicated in the output files across all submodules

Steps to Reproduce

  1. Clone the repository: https://github.com/ismoiliy98/bun-build-bug and checkout to commit d072e4e9d1d647bc6974619dac37e09f5c067216
  2. Install the dependencies: bun i
  3. Run the build command: bun build src/**/*.ts --outdir dist --splitting
  4. Check the generated files in the dist directory and observe the duplicated exports in every module

What is the expected behavior?

When using the --splitting option with a glob pattern in the entry option (e.g., src/**/*.ts), Bun should generate output files with correctly defined exports, ensuring that each export is only defined once in every module. The generated files should not contain any duplicate export declarations, and the build process should handle module splitting without any redundancy in the output

What do you see instead?

With the --splitting option enabled, the generated output files contain duplicated exports in every module. Each export is defined twice, leading to unnecessary redundancy in the bundled output. This issue occurs consistently across all submodules when using the glob pattern for the entry points

Example

Input:

// src/index.ts
export * from "./module";
// src/module.ts
export const greeting = "Hello, world!";

Output:

// dist/index.js
import {
  greeting
} from "./module.js";
export {
  greeting
};
// dist/module.js
var greeting = "Hello, world!";
export {
  greeting
}; // <= first export

export { greeting }; // <= second export

Additional information

  • The issue only occurs when the --splitting option is used in the build command
  • If I omit the --splitting option, everything works as expected, and no duplicate exports are generated
  • The problem arises specifically when a module folder contains an index.ts file that re-exports from other files, and those files also have their own exports
  • If I remove the index.ts file, the --splitting option works correctly, and no duplicate exports are present
  • The duplicated exports occur in every file within the module except for index.ts

This summarizes the key points I’ve observed so far

@ismoiliy98 ismoiliy98 added bug Something isn't working needs triage labels Oct 11, 2024
@nektro nektro added the bundler Something to do with the bundler label Oct 11, 2024
@RiskyMH RiskyMH added confirmed bug We can repo this issue and removed needs triage labels Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bundler Something to do with the bundler confirmed bug We can repo this issue
Projects
None yet
Development

No branches or pull requests

3 participants