Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use arbitrary node modules from clojurescript?

Is it possible to use arbitrary node.js modules in a clojurescript project? If yes, how do I go about including them? If not, why not?

like image 351
mushroom Avatar asked Jun 06 '14 23:06

mushroom


2 Answers

Yes, since late 2017. With shadow-cljs or Lumo now it's not problem to import npm modules in ClojureScript code anymore.

(ns app.main
  (:require ["dayjs"   :as dayjs]
            ["shortid" :as shortid]
            ["lodash"  :as lodash]
            ["lodash"  :refer [isString]]))

Read this topic for details: Guide on how to use/import npm modules/packages in ClojureScript?

like image 142
jiyinyiyong Avatar answered Sep 27 '22 16:09

jiyinyiyong


Yes, you can, there is nothing special about it:

(def fs (js/require "fs"))
(println (.readdirSync fs js/__dirname))

Be careful with the externs if you don't use optimizations none.

Edit: Does leiningen play with the various js package managers?:
Nope. Since the language does not have packages, it cannot know. You have to do js dependency management and lein deps too. There is a lein-npm and a lein-bower to help with integrating these two package managers.

like image 44
Joaquin Avatar answered Sep 27 '22 18:09

Joaquin