Skip to content

bun link -g creates broken symlink - package not linked to global node_modules #25746

@pokey

Description

@pokey

What version of Bun is running?

1.3.5

What platform is your computer?

Darwin x86_64 (macOS)

What steps can reproduce the bug?

  1. Create a new package:
mkdir my-cli && cd my-cli && bun init -y
  1. Update package.json to add a bin entry:
{
  "name": "my-cli",
  "module": "index.ts",
  "type": "module",
  "files": ["src"],
  "bin": {
    "my-cli": "src/cli.ts"
  },
  "devDependencies": {
    "@types/bun": "latest"
  },
  "peerDependencies": {
    "typescript": "^5"
  }
}
  1. Create src/cli.ts with a shebang:
mkdir src
echo '#!/usr/bin/env bun
console.log("hello");' > src/cli.ts
  1. Register and link globally:
bun link
bun link -g my-cli

What is the expected behavior?

The binary should be executable:

~/.bun/bin/my-cli  # should print "hello"

What do you see instead?

The command reports success but shows a FileNotFound error:

bun link v1.3.5 (1e86cebd)

installed my-cli@link:my-cli with binaries:
 - my-cli

Failed to install 1 package
[12.00ms] done
FileNotFound: failed linking dependency/workspace to node_modules for package my-cli

The symlink is created at ~/.bun/bin/my-cli, but it points to a non-existent location:

$ ls -la ~/.bun/bin/my-cli
lrwxrwxrwx  1 user  staff  48 Dec 29 13:34 /Users/user/.bun/bin/my-cli -> ../install/global/node_modules/my-cli/src/cli.ts

$ ls ~/.bun/install/global/node_modules/my-cli
ls: /Users/user/.bun/install/global/node_modules/my-cli: No such file or directory

The package is never symlinked into ~/.bun/install/global/node_modules/.

Additional information

Workaround: Manually create the missing symlink:

ln -s /path/to/my-cli ~/.bun/install/global/node_modules/my-cli

After this, the binary works correctly.

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