clojurebabashka

How to import function from another script in the same foder?


Lets say I have babashka script common.clj:

#!/usr/bin/env bb

(ns common)

(defn my-function []
  (println "do something"))

When I am trying to import it from another script:

#!/usr/bin/env bb

(ns example
  (:require [common :as c]))

(c/my-function)

Despite there is common.clj I get an error:

(:require [common :as c]))
^--- Could not locate common.bb, common.clj or common.cljc on classpath.

Is is possible to fix?


Solution

  • Just as the error states, you have to make sure that the directory where common.clj resides is located on the classpath.

    One way to do it with Babashka would be to add bb.edn with {:paths ["."]} in it.