oven-sh / bun

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

`bunx` doesn't recognize its `bunx` and not `bun` on Windows when installed via npm #10599

Open Jarred-Sumner opened 4 months ago

Jarred-Sumner commented 4 months ago

bunx prints the same help menu as bun on Windows:

PS C:\bun> bunx
Bun is a fast JavaScript runtime, package manager, bundler, and test runner. (1.1.5+b257a3097)

Usage: bun <command> [...flags] [...args]
PS C:\bun> bunx vite
error: Script not found "vite"

Additionally, scoop installs a bunx.cmd shim which should be unnecessary since bunx is a .exe file.

hanascript commented 4 months ago

Getting this problem as well. My work around is to use the bun create command then run bun install inside the project because it also doesn't create a bun.lock file. You can then delete the package-lock.json yourself. Hopefully they fix. For things like shadcn you will still get the issue if you try to use bun, I just use npx. Seems to still work for now

Vivelin commented 2 months ago

The documentation says bunx is an alias for bun x, and while bunx will give me the same "Script not found" message, bun x works just fine (Windows, v1.1.18).

fzkhan19 commented 2 weeks ago

Facing the same issue, if we run bunx.exe from under c:/users//.bun/bin, it works perfectly. But if we run it globally bunx considers itself as bun. I even tried removing path from system variables but it's somehow still working.

paperdave commented 2 weeks ago

how have you been installing bun. i have never been able to reproduce this. i'd love to fix this but i have nothing to go off of.

Vivelin commented 2 weeks ago

I think I used npm to install it?

paperdave commented 2 weeks ago

Additionally, scoop installs a bunx.cmd shim which should be unnecessary since bunx is a .exe file.

it does not?

image

additionally, this exe shim is part of scoop's design. if you want to avoid this indirection, you can install bun using it's powershell installer

powershell -c "irm bun.sh/install.ps1 | iex"

@Vivelin thanks for the fast reply. npm i -g bun reproduces it, and i think this also explains what jarred was on about with it being a cmd script. that is npm's design

image

oh i see exactly what is happening here

image

this is a mistake in our packaging for npm (not a fixable issue in bun.exe)

package.json bins have bun and bunx point to the same file, which would foward the executable name as they are symbolic links. on windows, they are not symbolic links, so the binary name isn't forwarded.

image

a temporary fix is to npm remove -g bun and use the above powershell script, that will also enable you to use bun upgrade properly.

fzkhan19 commented 1 week ago

FOUND THE SOLUTION!!!

PROBLEM: I'm using nvm on my machine so installing bun using npm i -g bun will create bun config files inside C:\Users\<username>\AppData\Roaming\nvm\v20.13.1 Filenames: bunx.cmd and bunx.ps1 Then inside C:\Users\<username>\AppData\Roaming\nvm\v20.13.1\node_modules You'll find a bun\bin folder, now for some reason there is no bunx.exe file here only bun.exe file is present.

SOLUTION: Replace the line where it says

"%dp0%\node_modules\bun\bin\bun.exe" %* with "%dp0%\node_modules\bun\bin\bunx.exe" %* in bunx.cmd and

# Support pipeline input if ($MyInvocation.ExpectingInput) { $input | & "$basedir/node_modules/bun/bin/bun.exe" $args } else { & "$basedir/node_modules/bun/bin/bun.exe" $args } with # Support pipeline input if ($MyInvocation.ExpectingInput) { $input | & "$basedir/node_modules/bun/bin/bunx.exe" $args } else { & "$basedir/node_modules/bun/bin/bunx.exe" $args }

Now to resolve the issue of missing bunx.exe you can use powershell utility to install bun then copy bunx.exe from C:\Users\<username>\.bun\bin\bunx.exe and paste it inside C:\Users\<username>\AppData\Roaming\nvm\v20.13.1\node_modules\bun\bin

*NOTE: v20.13.1 is the selected node version in nvm when I installed bun.