lumo

:lumo: Standalone ClojureScript environment. Currently at version 1.9.0
dotemacs 2019-10-27T10:37:44.001100Z

Hi With lumo 1.7.0

$ echo "{:foo :bar}" > resources/aha.edn
which is started via:
lumo -D aero:1.1.3 -c src:test -d
running this at the REPL:
(require '[aero.core :refer [read-config]])
(read-config "resources/aha.edn")
works as expected. Then tried it with 1.8.0 and that is fine too. But with 1.9.0 or 1.10.1, it fails with:
fs is not defined
         aero$core$read_config_into_tag_wrapper (evalmachine.<anonymous>:829:386)
         Function.aero.core.read_config.cljs$core$IFn$_invoke$arity$2 (evalmachine.<anonymous>:860:61)
         aero$core$read_config (evalmachine.<anonymous>:844:30)
         Function.aero.core.read_config.cljs$core$IFn$_invoke$arity$1 (evalmachine.<anonymous>:865:30)
         aero$core$read_config (evalmachine.<anonymous>:848:30)
         (evalmachine.<anonymous>:1:23)
         Script.runInThisContext (vm.cljs:90:20)
         Object.runInThisContext (vm.cljs:297:38)
         (<http://Object.It|Object.It>)
         (Object.lumo.repl.caching_node_eval)

dotemacs 2019-10-27T10:39:02.002100Z

My guess is that something changed between Lumo 1.8.0 and the subsequent versions that doesn’t pick up fs node module.

dotemacs 2019-10-27T10:39:23.002600Z

This aero version 1.1.3 is the latest stable.

dotemacs 2019-10-27T10:41:31.004Z

Any hints about what could be causing this would be much appreciated. I can will stick with Lumo 1.8.0 for time being. Thanks

futuro 2019-10-27T12:34:05.005300Z

When you open the latest lumo, what happens when you try to require the fs module?

dotemacs 2019-10-27T16:21:48.005700Z

Hey @futuro This is what happens: On Lumo 1.8

cljs.user=&gt; (require 'fs)
cljs.user=&gt; nil
cljs.user=&gt; (fs.readFile "resources/aha.edn" (fn [_ data] (println data)))
nil
cljs.user=&gt; #object[Buffer {:foo :bar}
]

dotemacs 2019-10-27T16:21:59.005900Z

On Lumo 1.10.1

cljs.user=&gt; (require 'fs)
nil
cljs.user=&gt; (fs.readFile "resources/aha.edn" (fn [_ data] (println data)))
fs is not defined
	 (evalmachine.&lt;anonymous&gt;:1:1)
	 Script.runInThisContext (vm.cljs:124:20)
	 Object.runInThisContext (vm.cljs:314:38)
	 (<http://Object.It|Object.It>)
	 (Object.lumo.repl.caching_node_eval)
	 (NO_SOURCE_FILE &lt;embedded&gt;:6029:9)
	 z (NO_SOURCE_FILE &lt;embedded&gt;:6030:22)
	 (NO_SOURCE_FILE &lt;embedded&gt;:6025:264)
	 Function.cljs.core.trampoline.cljs$core$IFn$_invoke$arity$1 (NO_SOURCE_FILE &lt;embedded&gt;:1927:142)
	 Function.cljs.core.trampoline.cljs$core$IFn$_invoke$arity$variadic (NO_SOURCE_FILE &lt;embedded&gt;:1927:280)

dotemacs 2019-10-27T16:22:20.006200Z

But then in the same REPL session:

cljs.user=&gt; (require '[cljs.nodejs :as nodejs])
nil
cljs.user=&gt; (def fs  (nodejs/require "fs"))
#'cljs.user/fs
cljs.user=&gt; (fs.readFile "resources/aha.edn" (fn [err data] (println data)))
nil
cljs.user=&gt; #object[Buffer {:foo :bar}
]

anmonteiro 2019-10-27T17:13:40.006900Z

@dotemacs I’m puzzled — what made you think that . would work to access a namespace’s functions?

anmonteiro 2019-10-27T17:14:07.007400Z

if you use (require 'fs) then use fs/readFile

anmonteiro 2019-10-27T17:14:14.007600Z

fs.readFile is not a thing for namespaces

futuro 2019-10-27T18:13:40.009900Z

@dotemacs reading the aero source, they’re using the fs/readFileSync form, and the only difference is (:require ["fs" :as fs]).

futuro 2019-10-27T18:14:25.011100Z

Given that the function access looks right, my guess is that the latest lumo doesn’t like something about the require form.

futuro 2019-10-27T18:15:25.012800Z

I don’t know enough about cljs requires and how they work in lumo to hypothesize past that, but hopefully it’s enough to get you moving in the right direction.

futuro 2019-10-27T18:15:47.013400Z

The aero maintainers may know more if you open an issue

dotemacs 2019-10-27T18:19:52.014300Z

@anmonteiro ok, sorry, my bad. But why does fs.readFile work for Lumo 1.8 and not for Lumo 1.9+?

anmonteiro 2019-10-27T18:20:06.014500Z

it might be an implementation detail

anmonteiro 2019-10-27T18:20:28.015Z

we’re not in control of what Node.js exposes in the scope

dotemacs 2019-10-27T18:20:38.015300Z

OK, thanks

dotemacs 2019-10-27T18:37:16.018500Z

@futuro I’ll open an issue for sure, thanks. But that require that you’ve shared above is in aero 1.1.3. Added here: https://github.com/juxt/aero/pull/59/files If I look in the code for aero 1.1.2, which used to work, for Lumo 1.7.0, it doesn’t work for Lumo 1.8.0. This particular code:

(require '[aero.core :refer [read-config]])
(read-config "resources/aha.edn")
That is invoked via:
lumo -D aero:1.1.2 -c src:test -d
From looking at the aero.core namespace at that release, 1.1.2, fs is not being required at all, but it is being used, like here: https://github.com/juxt/aero/blob/af40928fc77facc4927075c63b7262bc961b6761/src/aero/core.cljc#L359

futuro 2019-10-27T18:43:50.019100Z

Ah! I’d missed that you were on an older version.

futuro 2019-10-27T18:44:25.019900Z

Does your code work with aero 1.1.3?

futuro 2019-10-27T18:45:17.021300Z

If so, my guess is that older versions of lumo have the fs module available as part of environment, and newer versions don’t.

futuro 2019-10-27T18:45:58.022200Z

Which would explain the change is from aero 1.1.2->1.1.3

dotemacs 2019-10-27T18:46:50.023200Z

Regardless of the aero version used, the code works, up to Lumo 1.8. From Lumo 1.9+, the aero’s read-config throws an exception as per above.

dotemacs 2019-10-27T18:47:57.023900Z

How can I ensure that the fs module is part of the environment, so that aero continues to work correctly ?

dotemacs 2019-10-27T19:28:31.025Z

I’ve raised an issue on aero’s repo, adding this here in case somebody else stumbles upon this issue: https://github.com/juxt/aero/issues/80

futuro 2019-10-27T22:32:06.025800Z

No clue about fixing aero, but I suspect the maintainers will know.

👍 1