babashka / nbb

Scripting in Clojure on Node.js using SCI
Eclipse Public License 1.0
863 stars 52 forks source link

deps from nbb.edn are not in the nbb classpath by default when called by node #270

Closed raymcdermott closed 2 years ago

raymcdermott commented 2 years ago

Versions

nbb v1.0.139
nodejs 14 | 16 | 18
Linux version 5.4.0-126-generic (buildd@lcy02-amd64-072) (gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)) #142-Ubuntu SMP Fri Aug 26 12:12:57 UTC 2022 (Ubuntu 5.4.0-126.142-generic 5.4.203)

Minimal reproduction

I have published one here

Context

This problems surfaces when using nbb with AWS Lambdas where the module and artefacts are invoked directly with nodejs

Problem

When calling the module eg node some-lambda.mjs we see an error like this:

file:///home/ray/fc/repos/card-main/node_modules/nbb/lib/nbb_core.js:2214
2,null),new $APP.G(null,jt,new $APP.G(null,new $APP.G(null,$APP.Ul,new $APP.G(null,D,null,1,null),2,null),null,1,null),2,null),3,null),4,null),5,null),6,null)):null}finally{$APP.Wq()}}).then(function(){var P=$APP.z(a);return hx.h?hx.h(P,b):hx.call(null,P,b)}):Promise.reject(Error(["Could not find namespace: ",$APP.p.g(q)].join("")))}return Promise.resolve($APP.U.g(b))};
                                                                                                                                                                                                                                                                                   ^

Error: Could not find namespace: camel-snake-kebab.core
    at hx (file:///home/ray/fc/repos/card-main/node_modules/nbb/lib/nbb_core.js:2214:276)
    at file:///home/ray/fc/repos/card-main/node_modules/nbb/lib/nbb_core.js:2214:244
    at async file:///home/ray/fc/repos/card-main/card-get.mjs:5:21

Countermeasure

We can manually locate the deps using something like this:

find .nbb -type d -name nbb-deps
.nbb/.cache/e4754d38932a5ba3dcbfe8a138680e6ec55900db/nbb-deps

and add that to the module:

addClassPath(".nbb/.cache/e4754d38932a5ba3dcbfe8a138680e6ec55900db/nbb-deps")

This is not a satisfactory countermeasure as the location of the cache can change.

Expected behaviour

The dependencies should be included in the nbb classpath so that we avoid these errors