Search code examples
clojuredependenciesclojurescriptleiningenreagent

Adding dependencies to clojure projects using lein


Despite adding the desired dependency to my project.clj file,

(defproject word-tree "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}

  :dependencies [[org.clojure/clojure "1.10.1"]
                 [org.clojure/clojurescript "1.10.520"]
                 [clojure-opennlp "0.5.0"] ; <----------------------here
                 [reagent "0.8.1"]]
 ...

I am unable to access the functions that the dependency provides.

After referencing the namespace in one of my files,

(ns word-tree.suffix-tree
  (:require [clojure.string :as str]
            [opennlp.nlp :as nlp])) ; <-----this is the namespace of the dependency

I get this error:

No such namespace: opennlp.nlp, could not locate opennlp/nlp.cljs, opennlp/nlp.cljc, or JavaScript source providing "opennlp.nlp"

The weirdest part is that when I run lein deps :tree the dependency shows up!

$ lein deps :tree
...
[cider/piggieback "0.4.1" :scope "test"]
 [cljfmt "0.5.7"]
   [rewrite-clj "0.5.2"]
   [rewrite-cljs "0.4.3"]
 [clojure-complete "0.2.5" :exclusions [[org.clojure/clojure]]]
 [clojure-opennlp "0.5.0"] <------------------------------------------------here!!!
   [instaparse "1.4.9"]
   [org.apache.opennlp/opennlp-tools "1.9.0"]
 [figwheel-sidecar "0.5.19" :scope "test"]
...

For my project I really want to use this dependency but it's not working. Any advice would be most welcome. Thanks.


Solution

  • It seems to me the problem is that the library is for Clojure on the JVM only, and you are trying to use it on a ClojureScript project.

    No such namespace: opennlp.nlp, could not locate opennlp/nlp.cljs, opennlp/nlp.cljc, or JavaScript source providing "opennlp.nlp"

    The compiler tried to look for ClojureScript code (extension .cljs) or compatible with both Clojure and ClojureScript (extension .cljc) or plain JavaScript, but found none.