Skip to content

Build error: SWC fails to read source map for dist/index.js with Bun #317

@haydenbleasel

Description

@haydenbleasel

Description

When building a Next.js app that depends on chat@4.23.0 using Bun as the package manager, the SWC compiler fails with:

ERROR  failed to read input source map: failed to find input source map file "index.js.map"
  in "node_modules/.bun/chat@4.23.0/node_modules/chat/dist/index.js" file
  as either "node_modules/.bun/chat@4.23.0/node_modules/chat/dist/index.js.map"
  or with appended .map
    at crates/swc/src/lib.rs:398

Details

The source map file (dist/index.js.map) is present in the package and is valid JSON. The issue appears to be that SWC cannot resolve the source map through Bun's internal module cache path (node_modules/.bun/).

dist/index.js ends with:

//# sourceMappingURL=index.js.map

The file dist/index.js.map exists and is ~316KB of valid JSON, but SWC fails to locate it when the package is installed via Bun.

Reproduction

  1. Create a Next.js app using Bun as the package manager
  2. Install chat@4.23.0
  3. Import from chat in any server-side code
  4. Run next build

Environment

  • chat: 4.23.0
  • Next.js: 16
  • Bun: 1.3
  • macOS (Darwin 25.3.0)

Workaround

Adding chat to serverExternalPackages in next.config.ts avoids the error:

const nextConfig: NextConfig = {
  serverExternalPackages: ["chat"],
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions