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

bun build ignores import aliases (@/) when marking packages as external #16509

Open
zohayrslileh opened this issue Jan 18, 2025 · 0 comments
Open
Labels
bug Something isn't working bundler Something to do with the bundler confirmed bug We can reproduce this issue

Comments

@zohayrslileh
Copy link

What version of Bun is running?

1.1.45+196621f25

What platform is your computer?

Linux 6.12.9-200.fc41.x86_64 x86_64 unknown

What steps can reproduce the bug?

📝 Description
When using Bun.build() with packages: "external", import aliases (e.g., @/) are incorrectly treated as external dependencies instead of being bundled. This causes build errors when the alias is expected to be resolved within the project.


🔄 Steps to Reproduce

1️⃣ Build Configuration (build.ts)

Bun.build({
    entrypoints: ["index.ts"],
    packages: "external", // Mark all packages as external
    outdir: "./dist"
});

2️⃣ Source File Before Build (index.ts)

// Importing a Node.js built-in module (expected to remain external)
import path from "node:path";

// Importing a local module (expected to be bundled)
import notAliasModule from "./notAliasModule";

// Importing a module using an alias (expected to be bundled but incorrectly treated as external)
import aliasModule from "@/aliasModule";

console.log({ path, aliasModule, notAliasModule });

3️⃣ Output After Build (index.js)

// ✅ Node.js module is correctly kept external
import path from "node:path";

// ✅ Local module is correctly bundled
var notAliasModule_default = "Not Alias Module";

// ❌ Alias module is incorrectly treated as an external package instead of being bundled
import aliasModule from "@/aliasModule";

console.log({ path, aliasModule, notAliasModule: notAliasModule_default });

Would appreciate any guidance or confirmation if this is intended behavior! 🚀

What is the expected behavior?

❗ Expected Behavior

  • Node.js built-in modules (e.g., path) should remain external
  • Local relative imports (e.g., "./notAliasModule") should be bundled
  • Aliased imports (@/) should also be bundled, just like relative imports. However, they are being incorrectly marked as external

What do you see instead?

🏷️ Suggested Fix

  • Ensure that import aliases defined in tsconfig.json (or equivalent) are correctly resolved and bundled when using Bun.build(), even when packages: "external" is specified.

Additional information

No response

@zohayrslileh zohayrslileh added bug Something isn't working needs triage labels Jan 18, 2025
@paperclover paperclover added confirmed bug We can reproduce this issue bundler Something to do with the bundler and removed needs triage labels Jan 18, 2025
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 reproduce this issue
Projects
None yet
Development

No branches or pull requests

2 participants