Fork me on GitHub
#nbb
<
2024-04-16
>
eval202011:04:35

I’m bundling a script using bun. But when using dependencies things go wrong:

$ bun run --bun nbb bundle sqlite.cljs -o out.mjs && bun build out.mjs --compile --outfile cli
  [47ms]  bundle  12 modules
  [43ms] compile  cli
~/src/nbb/examples/bun (patch-1 *=)
$ ./cli
error: Cannot find module "./nbb_deps.js" from "/$bunfs/root/cli"
Anyone an idea what’s going on? Full rep(r)o: https://github.com/eval/nbb/tree/bundle-deps/examples/bun

borkdude11:04:42

I don't get the example, sorry

borkdude11:04:52

oh there's a link

borkdude11:04:45

when cloning your repo, I'm getting:

$ bun run --bun nbb bundle sqlite.cljs -o out.mjs
An error occurred when calling (nbb.impl.bundler/init)
----- Error --------------------------------------
Type:     ENOENT
Message:  No such file or directory
/private/tmp/nbb/examples/bun/node_modules/nbb/lib/nbb_main.js

eval202011:04:39

are you on the patch-1 branch?

eval202011:04:47

sorry, the bundle-deps branch?

borkdude11:04:37

in which directory are you running this

eval202011:04:40

running from path examples/bun

eval202011:04:48

sorry for the confusion

borkdude11:04:54

the sqlite.cljs file doesn't exist here

borkdude11:04:49

needed to run bun install first

👍 1
borkdude11:04:33

ok, at least this runs:

$ bun --bun out.mjs
["SELECT a, b, c FROM foo WHERE foo.a = ?" "baz"]
#js {:runtime "Bun"}

borkdude11:04:24

$ bun build out.mjs --compile --outfile cli
  [74ms]  bundle  12 modules
 [153ms] compile  cli
borkdude@m1-3 /tmp/nbb/examples/bun (bundle-deps?) $ ./cli
error: Cannot find module "./nbb_deps.js" from ""
Seems a bun error to me

eval202011:04:01

yep indeed. I also found that vendoring honey-sql works as well - bundled with bun that is:

$ cp -r .nbb/.cache/ab0dc41671be63d160b05b56f910fe19ba103da3/nbb-deps/honey vendor/
$ bun run --bun nbb -cp vendor bundle sqlite.cljs -o out.mjs && bun build out.mjs --compile --outfile cli

borkdude11:04:03

$ bun build out.mjs --outfile cli
2 | import * as bun_COLON_sqlite from 'bun:sqlite'
                                      ^
error: Could not resolve: "bun:sqlite". Maybe you need to "bun install"?

eval202011:04:12

yeah the --compile flag is needed for that to work

borkdude11:04:40

file an issue with bun I'd say

borkdude11:04:21

the weird thing is that nbb_deps.js isn't mentioned anywhere in out.mjs

borkdude11:04:19

Ah it's something in nbb itself:

/lib/nbb_deps.js

borkdude11:04:38

Ah I got it:

borkdude@m1-3 /tmp $ ./cli
["SELECT a, b, c FROM foo WHERE foo.a = ?" "baz"]
#js {:runtime "Bun"}

borkdude11:04:54

the issue is that nbb tries to resolve dependencies when there is a relative nbb.edn file

borkdude11:04:15

so if you move this binary to another place without nbb.edn, then it's not doing that

eval202011:04:27

All in all a nice single executable for working with sqlite 🌟

borkdude11:04:43

The startup of just hello world is around 100ms on my machine, quite ok

$ time ./cli
Hello world

eval202012:04:55

yep. The sqlite-example 200ms on my machine.

borkdude12:04:33

same here. the 100ms is the loading/interpreting of honeysql

eval202012:04:01

ah, that adds a lot indeed. Is there any way to instruct nbb that it shouldn’t bother with nbb.edn?

eval202012:04:55

I mean: how would that look like, it’s not possible currently.

borkdude12:04:02

I think nbb bundle should add something to disable that, probably

eval202012:04:06

…an extra flag to bundle (?)

borkdude12:04:34

There is an initialize function in src/nbb/api.cljs which processes this nbb.edn stuff Perhaps we can add another API function to disable this or an option to loadFile, something like:

import { loadFile } from 'nbb';
loadFile("foo.cljs", {disableConfig: true})
or whatever

eval202008:04:30

Started some POC to do this via a flag for bundle:

nbb bundle sqlite.cljs -o out.mjs --disable-config
which emits await loadString(",,,," , {disableConfig: true}) . PR in the making

borkdude08:04:17

I think bundle should always disable the config, I think? I don't see the need for a flag

eval202008:04:08

ah that makes sense