oven-sh / bun

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

bun -i/--install=fallback doesn't fallback #5783

Open mnpenner opened 1 year ago

mnpenner commented 1 year ago

What version of Bun is running?

1.0.26+c75e768a6

What platform is your computer?

Linux 4.4.0-19041-Microsoft x86_64 x86_64

What steps can reproduce the bug?

cd "$(mktemp -d)"
mkdir node_modules
nano cow.ts

Paste this script:

import { say } from "cowsay";
console.log(say({ text: "grazing on your buns" }));

Save (ctrl+x).

Try to run it:

bun -i cow.ts

Get error:

error: Cannot find package "cowsay" from "/tmp/tmp.uBumgYS66f/cow.ts"

Note the mkdir node_modules step is key. It won't fallback when it sees that dir even though the docs suggest that it should. bun --install=force cow.ts doesn't work either.

What is the expected behavior?

Should auto-install cowsay because it's clearly missing from the node_modules dir.

What do you see instead?

error: Cannot find package "cowsay" from "/tmp/tmp.uBumgYS66f/cow.ts"

Additional information

I'm using WSL if it matters.

traviscooper commented 8 months ago

Any progress on this at all? Amazing feature, but haven't seen it working even in the latest.

pyronaur commented 7 months ago

This also doesn't work if node_modules is present in a parent directory 😞

PhilBladen commented 3 months ago

Updating this, I have found that Bun does not fallback or install on running a script (even with --install force ), even when there is no node_modules directory present. This is still true with or without a package.json. I am running on Windows 11.

andsens commented 3 months ago

@PhilBladen

even when there is no node_modules directory present

This part works for me in 1.0.17, but force does not seem to get bun to ignore any parent node_modules directories.

andsens commented 3 months ago

OK, I bisected a little. --install=force stopped working in v1.0.0. v0.8.1 respects the cli option.

PhilBladen commented 3 months ago

@andsens thanks for your prompt. I have done some more experimenting and my results match yours. It turns out in my previous message that there was a sneaky node_modules hiding several folders up.

In summary:

I have, however, discovered another issue in that auto-installed modules aren't loadable: I created the following test.js file at the top of my filesystem (no node_modules present):

import * as cowsay from "cowsay";
console.log(cowsay.say({text: "hi"}));

I ran with bun test.js and I get the following error error: Unexpected while resolving package "cowsay" from "D:\test.js" If I run bun i cowsay first, it works fine.

Using Bun v1.1.18 and Windows 11.