oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.28k stars 2.69k forks source link

bun not running local package bin #5075

Open jdion84 opened 1 year ago

jdion84 commented 1 year ago

What version of Bun is running?

1.0.0+822a00c4d508b54f650933a73ca5f4a3af9a7983

What platform is your computer?

Darwin 22.6.0 arm64 arm

What steps can reproduce the bug?

create file my_modules/bunclitest/package.json:

{
  "name": "bunclitest",
  "module": "index.ts",
  "type": "module",
  "bin": {
    "bunclitest": "bin.js"
  }
}

create file my_modules/bunclitest/bin.js:

#!/usr/bin/env node

console.log("hello bin");

open my_modules dir in terminal and run bun link

open project root folder and run bun link bunclitest --save

run bunx myclitest

nothing is outputted to console.

What is the expected behavior?

hello bin should be outputted to console when running bunx bunclitest

What do you see instead?

nothing

Additional information

No response

cyfung1031 commented 1 year ago

Same issue. From my case, error: missing script XXXXX is printed.

I believe this is MacOS specific bug.

futured-it commented 10 months ago

Yeah. Same thing, on Mac too. I guess, bun link ... simply doesn't register your project to bash commands as Node does.

futured-it commented 10 months ago

I guess, as a temporary solution you could link it with Node.js using npm link, and add #!/usr/bin/env bun inside of your JS (or TS) runtime file. That's stupid, but probably it'll work.

futured-it commented 10 months ago

I did some researches and realised that the fix is so easy: You should use string as a bin value, not object, so instead of this:

{
  "name": "bunclitest",
  "module": "index.ts",
  "type": "module",
  "bin": {
    "bunclitest": "bin.js"
  }
}

do like this:

{
  "name": "bunclitest",
  "module": "index.ts",
  "type": "module",
  "bin": "bin.js"
}
jdion84 commented 10 months ago

You should use string as a bin value, not object

no, you shouldnt

futured-it commented 10 months ago

You should use string as a bin value, not object

no, you shouldnt

Well, in my situation that's fixed the problem. It doesn't work with object on my and these peoples machines for some reasons.

cpakken commented 4 months ago

bin commands still not working with bun linked packages as of version 1.18

ghost commented 3 months ago

I figured this out

after you add the bin to the local package, just do bun link on it again

mkv27 commented 1 month ago

If you install bun via homebrew and do nothing else is not going to work. Installing via curl -fsSL https://bun.sh/install | bash solve the problem