1
votes

I'm trying to use Node.js + ClojureScript, and I found an article for it.

http://www.mase.io/code/clojure/node/2015/01/24/getting-started-with-clojurecript-and-node/

Following the instruction to find this error:

  process.binding('evals').NodeScript.runInThisContext.call(
          ^
Error: No such module: evals
    at Error (native)

The issue seems that I need to use old version of node: https://groups.google.com/forum/#!topic/clojurescript/VneLWVpwe6o and https://github.com/kanso/kanso/issues/422

Mine is 0.12.7

pow> node --version
v0.12.7

In this case, I may need to use old version of node, but better yet, is there a way to bypass this issue? If none exists, how to use the old version of node.js in Mac OS X?

Edit

Following https://github.com/creationix/nvm, I could install 0.10.32 version of node.js.

pow> nvm install 0.10.32
pow> node --version
v0.10.32

However, it gives me another error message:

pow> node entrypoint.js 
Hello world!

/Users/smcho/Desktop/clojurescript/pow/out/server/cljs/core.js:12133
var fixed_arity = f.cljs$lang$maxFixedArity;
                   ^
TypeError: Cannot read property 'cljs$lang$maxFixedArity' of null

Edit2

The error was because I forgot to update the core.cljs module to include ((set! *main-cli-fn* -main). It's mentioned in the original article, together with https://groups.google.com/forum/#!topic/clojurescript/DYpsiCmsyIs and https://github.com/clojure/clojurescript/wiki/Quick-Start#running-clojurescript-on-nodejs.

2
If you found a solution consider adding it as an answer and marking it as solution :) - Martin Klepsch

2 Answers

1
votes

From the post, there are two ways to make it working, with Mac OSX, the two approaches require different version of node.js, and this is not clearly explained in the post.

The version that works with old node.js

(defproject pow "0.1.0-SNAPSHOT"
    :description "FIXME: write this!"
    :url "http://example.com/FIXME"

    :dependencies [[org.clojure/clojure "1.6.0"]
                                 [org.clojure/clojurescript "0.0-2725"]]

    :node-dependencies [[source-map-support "0.2.8"]]

    :plugins [[lein-cljsbuild "1.0.4"]
                        [lein-npm "0.4.0"]]

    :source-paths ["src" "target/classes"]

    :clean-targets ["out/server/pow" "out/server/pow.js"]

    :cljsbuild {
        :builds [{:id "server"
                            :source-paths ["src/server"]
                            :compiler {
                                :main pow.core
                                :output-to "out/server/pow.js"
                                :output-dir "out/server"
                                :optimizations :none
                                :target :nodejs
                                :cache-analysis true
                                :source-map true}}
                         ]})
// entrypoint.js
require("./out/server/goog/bootstrap/nodejs");
require("./out/server/pow");
require("./out/server/pow/core");
#!/bin/bash
lein new mies pow
cd pow
cp ../_project.clj project.clj

mkdir src/server
mv src/pow src/server/

lein cljsbuild once
cp ../entrypoint.js .

/Users/smcho/.nvm/v0.10.32/bin/node entrypoint.js

The version that works with new node.js

:optimizations :simple <-
:source-map "out/server/pow.js.map" <-

Run first part of runme.sh

lein new mies pow
cd pow
cp ../_project.clj project.clj

mkdir src/server
mv src/pow src/server/
(ns pow.core
    (:require
                        [clojure.browser.repl :as repl]))

(enable-console-print!)

(defn -main []
    (println "Hello world!"))

(set! *main-cli-fn* -main)
cd pow
lein cljsbuild once
node out/server/pow.js

One more note

I wanted to use ClojureScript/Node.js in order to test clojureScript code without using web browsers. I found LightTable, and a good tutorial about it. All I need to is open the LightTable, connect to LightTable UI as an output, then execute the script. So, I have much less reason to use ClojureScript/Node.js as of now.

enter image description here

0
votes

I fixed this with two steps:

1) Declaring a main function

(ns testproj.core
  (:require
            [clojure.browser.repl :as repl]))

(enable-console-print!)

(defn -main []
  (println "Hello world!"))

(set! *main-cli-fn* -main)

2) Setting optimizations: simple in my project.clj, as noted at the very bottom of this blog post. For reasons unknown to me, optimizations: none breaks things.