Skip to content

luaBundle includes duplicate modules when using pnpm/yarn workspace symlinks #1683

@ChouUn

Description

@ChouUn

Bug Report

Description

When using luaBundle in a pnpm (or yarn) workspace monorepo, the same package gets bundled multiple times under different module keys if it's referenced both directly and transitively through symlinked dependencies.

Reproduction

Setup: pnpm workspace monorepo with three packages:

  • pkg-a — base library (buildMode: "library")
  • pkg-b — depends on pkg-a (buildMode: "library")
  • pkg-c — depends on pkg-a and pkg-b (luaBundle entry point)

pnpm symlink layout:

packages/pkg-c/node_modules/pkg-a -> ../../pkg-a   (real path: packages/pkg-a)
packages/pkg-c/node_modules/pkg-b -> ../../pkg-b
packages/pkg-b/node_modules/pkg-a -> ../../pkg-a   (same real path!)

Result: bundle.lua contains pkg-a twice:

____modules = {
["lua_modules.pkg-a.dist.index"] = function(...)          -- direct dep from pkg-c
    -- ... pkg-a code ...
end,
["lua_modules.pkg-b.node_modules.pkg-a.dist.index"] = function(...)  -- transitive dep via pkg-b
    -- ... identical pkg-a code ...
end,
}

Expected: pkg-a should appear only once in the bundle.

Root Cause

In src/transpilation/resolve.ts, the enhanced-resolve resolver is configured with symlinks: false (to preserve node_modules path detection). The deduplication in resolvedFiles and processedDependencies uses string-based path comparison. Since pnpm symlinks create different filesystem paths for the same physical file, the same module passes deduplication checks and gets bundled multiple times.

Environment

  • typescript-to-lua: 1.33.2
  • pnpm: 10.28.0
  • OS: Linux (WSL2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions