microsoft/typescript-go · critical

bundled: %v does not exist; this executable may be misplaced

Error message

bundled: %v does not exist; this executable may be misplaced

What it means

In the noembed build (libs shipped as external files instead of embedded in the binary), libPath() panics when it cannot find a 'lib.d.ts' file next to the executable directory. This is a deployment-integrity panic raised lazily via sync.OnceValue: the first use of bundled library files aborts the process, not returns an error.

Source

Thrown at internal/bundled/noembed.go:40

var executableDir = sync.OnceValue(func() string {
	exe, err := osutil.Executable()
	if err != nil {
		panic(fmt.Sprintf("bundled: failed to get executable path: %v", err))
	}
	exe = tspath.NormalizeSlashes(exe)
	exe = osvfs.FS().Realpath(exe)
	return tspath.GetDirectoryPath(exe)
})

var libPath = sync.OnceValue(func() string {
	if testing.Testing() {
		return TestingLibPath()
	}
	dir := executableDir()

	libdts := tspath.CombinePaths(dir, "lib.d.ts")
	if info := osvfs.FS().Stat(libdts); info == nil {
		panic(fmt.Sprintf("bundled: %v does not exist; this executable may be misplaced", libdts))
	}

	return dir
})

func IsBundled(path string) bool {
	return false
}

View on GitHub (pinned to 1bcfa18d79)

Solutions

  1. Keep the executable in its original directory so lib.d.ts sits next to it (exe_dir/lib.d.ts must exist)
  2. Or rebuild with the embedded-libs build tag so library files are compiled into the binary and no external file is needed
  3. For tests, ensure the test setup provides the testing lib path (testing.Testing() branch) — do not run library-needing code before setup
  4. In container images, COPY the whole distribution directory, not just the binary

Example fix

# before
COPY bin/tsc /usr/local/bin/
RUN tsc --version   # panics: no /usr/local/lib.d.ts

# after: ship the whole distribution (exe + lib.d.ts siblings)
COPY dist/ /opt/tsgo/
RUN ln -s /opt/tsgo/tsgo /usr/local/bin/tsgo
Defensive patterns

Strategy: validation

Validate before calling

// Run before any compiler use: verify the noembed distribution is intact.
func checkBundledLibs(exeDir string) error {
    if _, err := os.Stat(filepath.Join(exeDir, "lib.d.ts")); err != nil {
        return fmt.Errorf("lib.d.ts missing next to executable %s; ship the full distribution or use the embedded build: %w", exeDir, err)
    }
    return nil
}

Prevention

When it happens

Trigger: Running the compiled noembed binary after moving/copying it away from its lib directory; Docker images or install scripts that ship only the executable; invoking with a cwd that is not the binary's directory while the lib directory was left behind; test binaries that do not set up TestingLibPath.

Common situations: CI pipelines copying a single binary artifact into a slim image; 'go build' output moved to /usr/local/bin without ../lib.d.ts; renaming or repackaging the distribution so exe and lib.d.ts are no longer siblings.

Related errors


AI-assisted analysis of microsoft/typescript-go@1bcfa18d79 (2026-08-16). Data as JSON: /api/errors/35c9d732020b9a9b. Report an issue: GitHub.