bun icon indicating copy to clipboard operation
bun copied to clipboard

Cannot find package "tls"

Open wmelton opened this issue 2 years ago • 1 comments

What version of Bun is running?

0.4.0

What platform is your computer?

Darwin 21.3.0 x86_64 i386

What steps can reproduce the bug?

Trying out bun + nats - looks like there could be an issue with resolving node-native packages when require is used in a dependency, or a more generic dependency resolution error.

To reproduce:

docker pull nats

docker run -d --name nats-main -p 4222:4222 -p 6222:6222 -p 8222:8222 nats

Create a file called publish.js (for example) and set its contents thusly:

import { connect, StringCodec } from "nats";

(async () => {
// to create a connection to a nats-server:
const nc = await connect({ servers: "localhost:4222" });

// create a codec
const sc = StringCodec();


nc.publish("hello", sc.encode("world"));
nc.publish("hello", sc.encode("again"));
})();

Then run:

bun publish.js

What is the expected behavior?

Script file would run same as node publish.js does

What do you see instead?

Cannot find package "tls" from ".../node_modules/nats/lib/src/node_transport.js"

Additional information

If you run bun install tls the error is resolved, but then it can't find the dns package used in nats. Given that nats package.json file doesn't include tls or dns as a defined dependency, my gut says this is an issue related to bun not knowing these are native node modules that need to be pulled in that a node developer would likely never name explicitly in a project's package.json file.

That said, if you run bun install <dep> to fix it, the resolve logic then throws a new error that you can't get past:

44 |   function workaround_require(path) {
45 |     if(/^\.\//.test(path) || /^\.\.\//.test(path))
46 |       path = path_lib.resolve(mod_dir, path);
47 | 
48 |     try       {
49 |       return real_require(path)
                 ^
TypeError: undefined is not an object

wmelton avatar Jan 03 '23 01:01 wmelton

tls isn't implemented yet

Jarred-Sumner avatar Jan 03 '23 01:01 Jarred-Sumner

I encountered the same when using nats on [email protected], and after running on canary (at 7fa023b), I now run into #1794.

danscan avatar Jan 14 '23 20:01 danscan

@danscan can you give it another try?

Jarred-Sumner avatar Jan 15 '23 18:01 Jarred-Sumner

Worked like a charm on canary! Incredible support and response time – all around.

During the time I spent looking into workarounds and considering temporarily using Node to work around this, it was resolved. It's hard to state how awesome that is!

danscan avatar Jan 15 '23 19:01 danscan

This works on 0.5.1 (https://github.com/oven-sh/bun/commit/ff6fb587f6c253c7bc849071ace593a473da5370) - good job implementing so fast!

wmelton avatar Jan 20 '23 23:01 wmelton