nbb 2023-06-27

I'm trying to call local javascript code from file f.js on nbb project. I tried (:require ["./f" :refer [someFunction]] and was expecting it to load from the nbb project root dir, where nbb.edn is located, but since there is a "src" folder configuration in nbb.edn it's loading the root from there. It's a little different from nodejs loading mechanism. (I've tested with : nbb (global) and pnpx nbb (local) both are loading from "src") What is the advised way to javascript code co-exist on a nbb project ?

A relative path is loaded relative to the file you’re loading from

Similar to JS

Embarassing. You're right.

(traverse ast #js {:FunctionDeclaration identity }) is generating the following error: :message "c.call is not a function", :data {:type :sci/error, :line 29, :column 5, :message "c.call is not a function", :sci.impl/callstack #object[cljs.core.Volatile {:val ({:line 29, :column 5, :ns #object[Ur js-cljs.astutils-test], It's a babel function https://babeljs.io/docs/babel-traverse that is imported as ["@babel/traverse" :as traverse] It expects an object with methods. I've stripped the code and passed identity just for testing.

I did (js/console.log traverse) and it is a function. The code is executed with nbb --debug -cp test -m nextjournal.test-runner

Try adding $default to the libname

"@babel/traverse$default" same result

["@babel/traverse" :refer [default]] invoking (default) instead of traverse gives same message c.call is not a function

Interesting, Now the import is as ["@babel/traverse$default" :as traverse] and I actually hit the function by doing ((j/get traverse :default ) )

So two defaults one from require one from calling

user=> (require '["@babel/traverse" :as t])
nil
user=> t/
t/Hub         t/NodePath    t/Scope       t/__esModule  t/default     t/visitors

I'll try to make the minimal traverse example from their README to work

oh yikes, you needed to do a double default, ok

😄 1

safetyfull defaults

what's that?

Joking, two defaults

it has something to do with typescript weirdness

So beautiful. require type l/ tab expansion

🤩 4