Fork me on GitHub
#nbb
<
2023-06-27
>
geraldodev11:06:14

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 ?

borkdude11:06:36

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

borkdude11:06:44

Similar to JS

geraldodev12:06:46

Embarassing. You're right.

geraldodev13:06:24

(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.

geraldodev13:06:12

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

borkdude13:06:23

Try adding $default to the libname

geraldodev13:06:49

"@babel/traverse$default" same result

geraldodev13:06:27

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

geraldodev14:06:30

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

geraldodev14:06:40

So two defaults one from require one from calling

borkdude14:06:51

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

borkdude14:06:19

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

geraldodev14:06:16

It's working

borkdude14:06:44

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

😄 2
geraldodev14:06:04

safetyfull defaults

borkdude14:06:31

what's that?

geraldodev15:06:37

Joking, two defaults

borkdude15:06:10

it has something to do with typescript weirdness

geraldodev22:06:05

So beautiful. require type l/ tab expansion

8