This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-04-16
Channels
- # announcements (1)
- # architecture (319)
- # babashka (27)
- # beginners (101)
- # biff (1)
- # calva (30)
- # cider (6)
- # clj-kondo (38)
- # clojure (41)
- # clojure-boston (1)
- # clojure-europe (80)
- # clojure-nl (1)
- # clojure-norway (21)
- # clojure-uk (4)
- # community-development (7)
- # conjure (1)
- # data-science (18)
- # datalevin (6)
- # datascript (30)
- # datomic (2)
- # events (2)
- # fulcro (1)
- # graalvm (3)
- # holy-lambda (2)
- # hyperfiddle (10)
- # jobs (3)
- # lsp (2)
- # malli (9)
- # matcher-combinators (3)
- # missionary (72)
- # nbb (40)
- # off-topic (1)
- # other-languages (14)
- # planck (5)
- # re-frame (2)
- # releases (4)
- # rewrite-clj (22)
- # shadow-cljs (3)
- # sql (2)
- # squint (17)
- # yamlscript (1)
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/bunwhen 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
ok, at least this runs:
$ bun --bun out.mjs
["SELECT a, b, c FROM foo WHERE foo.a = ?" "baz"]
#js {:runtime "Bun"}
$ 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 meyep 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
$ 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"?
Ah I got it:
borkdude@m1-3 /tmp $ ./cli
["SELECT a, b, c FROM foo WHERE foo.a = ?" "baz"]
#js {:runtime "Bun"}
the issue is that nbb tries to resolve dependencies when there is a relative nbb.edn
file
so if you move this binary to another place without nbb.edn, then it's not doing that
The startup of just hello world is around 100ms on my machine, quite ok
$ time ./cli
Hello world
ah, that adds a lot indeed. Is there any way to instruct nbb that it shouldn’t bother with nbb.edn?
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 whateverStarted 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