<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged nodejs</title>
<link>https://ask.clojure.org/index.php/tag/nodejs</link>
<description></description>
<item>
<title>How to transform js/Error to a clojurescript map?</title>
<link>https://ask.clojure.org/index.php/13176/how-to-transform-js-error-to-a-clojurescript-map</link>
<description>&lt;p&gt;I'm getting a &lt;code&gt;js/Error&lt;/code&gt; in my &lt;code&gt;catch&lt;/code&gt; form of &lt;code&gt;try/catch&lt;/code&gt;.  I was doing some repl work to see what I can understand about &lt;code&gt;js/Error&lt;/code&gt;s.  What I don't understand is why &lt;code&gt;(js-&amp;gt;clj js-err)&lt;/code&gt; just returns the same &lt;code&gt;js/Error&lt;/code&gt; object.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(def js-err (js/Error. &quot;testing&quot;))

js-err
;; =&amp;gt; #object[Error Error: testing]
(js-&amp;gt;clj js-err)
;; =&amp;gt; #object[Error Error: testing]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;evaluating &lt;code&gt;js-err&lt;/code&gt; and &lt;code&gt;(js-&amp;gt;clj js-err)&lt;/code&gt; result in the same thing.&lt;/p&gt;
&lt;p&gt;Here are the properties on &lt;code&gt;js-err&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(.getOwnPropertyNames js/Object js-err)
;; =&amp;gt; #js[&quot;stack&quot; &quot;message&quot;]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;what I want or expect to happen:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(js-&amp;gt;clj js-err)
;; =&amp;gt; {:message &quot;testing&quot;
;;     :stack &quot;blah\nblah&quot;}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Could someone explain why &lt;code&gt;js-&amp;gt;clj&lt;/code&gt; doesn't give me the object data as a map, and is there a idiomatic way to accomplish turning that object into a map?&lt;/p&gt;
&lt;p&gt;This is in the nodejs host&lt;/p&gt;
</description>
<category>ClojureScript</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13176/how-to-transform-js-error-to-a-clojurescript-map</guid>
<pubDate>Mon, 21 Aug 2023 14:54:16 +0000</pubDate>
</item>
<item>
<title>Not recognized function using Photon library with node.js</title>
<link>https://ask.clojure.org/index.php/9709/not-recognized-function-using-photon-library-with-node-js</link>
<description>&lt;p&gt;I need to use this library &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/silvia-odwyer/photon&quot;&gt;https://github.com/silvia-odwyer/photon&lt;/a&gt; and I use this example &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/minimal-xyz/minimal-shadow-cljs-nodejs&quot;&gt;https://github.com/minimal-xyz/minimal-shadow-cljs-nodejs&lt;/a&gt; as a starting point and I want to replicate this piece of code to test it:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;   var fs = require('fs');

var photon = require(&quot;@silvia-odwyer/photon-node&quot;);

const fetch = require('node-fetch');
global.fetch = fetch;

function grayscaleImage() {
    // read file, then convert to base64
    var base64 = fs.readFileSync(`input.png`, { encoding: 'base64' });
    let data = base64.replace(/^data:image\/(png|jpg);base64,/, &quot;&quot;);

    // convert base64 to PhotonImage
    var phtn_img = photon.PhotonImage.new_from_base64(data);

    photon.grayscale(phtn_img);

    // get base64 from filtered image, and write 
    let output_base64 = phtn_img.get_base64();
    let output_image_name = &quot;output.png&quot;;
    var output_data = output_base64.replace(/^data:image\/\w+;base64,/, '');

    fs.writeFile(output_image_name, output_data, {encoding: 'base64'}, function(err) {
    });
    console.log(`Saved ${output_image_name}`);

}

grayscaleImage();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So I wrote this&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns server.main
  (:require [&quot;@silvia-odwyer/photon-node&quot; :as sop]
                    [&quot;fs&quot; :as fs]
                    [&quot;node-fetch&quot; :as nf]
                    [clojure.string :as string]))

(defn main! []
  (let [base64 (fs/readFileSync &quot;input.png&quot; #js {:encoding &quot;base64&quot;})
        data (.replace base64 #&quot;^data:image/(png|jpg);base64,&quot; &quot;&quot;)
        phtn-img (sop/PhotonImage.new_from_base64 data)
        phtn-img (sop/grayscale phtn-img)
        output-base64 (sop/get_base64 phtn-img)]
    (println output-base64)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;but when I run &lt;br&gt;
'shadow-cljs release app' and ' node target/main.js'&lt;br&gt;
It throws:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    C:\Users\usuario\desktop\clojure\minimal-shadow-cljs-nodejs\target\mai
n.js:230
Vc.prototype.Z=B;Vc.prototype.J=function(a,b){return ob(b,&quot;()&quot;)};ra.pr
ototype.Z=B;ra.prototype.J=function(a,b,c){return Te(this,Se,b,c)};Ie.
prototype.Z=B;Ie.prototype.J=function(a,b,c){return Ke(b,Se,&quot;(&quot;,&quot; &quot;,&quot;)
&quot;,c,this)};tc.prototype.Z=B;tc.prototype.J=function(a,b,c){return Ke(b
,Se,&quot;(&quot;,&quot; &quot;,&quot;)&quot;,c,this)};&quot;undefined&quot;!==typeof console&amp;amp;&amp;amp;za();za();var y
a=new Qb(null,&quot;print-length&quot;,&quot;print-length&quot;,1931866356),sa=new Qb(null
,&quot;flush-on-newline&quot;,&quot;flush-on-newline&quot;,-151457939),ua=new Qb(null,&quot;met
a&quot;,&quot;meta&quot;,1499536964),Ve=new Qb(null,&quot;fallback-impl&quot;,&quot;fallback-impl&quot;,-
1501286995),ta=new Qb(null,&quot;readably&quot;,&quot;readably&quot;,1129599760),Ue=new Qb
(null,&quot;alt-impl&quot;,&quot;alt-impl&quot;,670969595),va=new Qb(null,&quot;dup&quot;,&quot;dup&quot;,5562
98533),Le=new Qb(null,&quot;more-marker&quot;,&quot;more-marker&quot;,-14717935);var af=re
quire(&quot;@silvia-odwyer/photon-node&quot;);var cf=require(&quot;fs&quot;);require(&quot;node
-fetch&quot;);pd(function(){$e(qc([&quot;App loaded!&quot;]));$e(qc([&quot;asdasd&quot;]));var
a=cf.readFileSync(&quot;input.png&quot;,{encoding:&quot;base64&quot;}).replace(/^data:imag
e\/(png|jpg);base64,/,&quot;&quot;);a=af.PhotonImage.new_from_base64(a);a=af.gra
yscale(a);a=af.get_base64(a).replace(/^data:image\/\w+;base64,/,&quot;&quot;);re
turn $e(qc([a]))},process.argv.slice(2));

TypeError: af.get_base64 is not a function
    at Function.&amp;lt;anonymous&amp;gt; (C:\Users\usuario\desktop\clojure\minimal-
shadow-cljs-nodejs\target\main.js:230:1066)
    at pd (C:\Users\usuario\desktop\clojure\minimal-shadow-cljs-nodejs
\target\main.js:112:412)
    at C:\Users\usuario\desktop\clojure\minimal-shadow-cljs-nodejs\tar
get\main.js:230:850
    at Object.&amp;lt;anonymous&amp;gt; (C:\Users\usuario\desktop\clojure\minimal-sh
adow-cljs-nodejs\target\main.js:231:3)
    at Module._compile (internal/modules/cjs/loader.js:1015:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1
035:10)
    at Module.load (internal/modules/cjs/loader.js:879:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/r
un_main.js:60:12)
    at internal/main/run_main_module.js:17:47
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Saying that get_base64 is not a function...&lt;br&gt;
doc: &lt;a rel=&quot;nofollow&quot; href=&quot;https://docs.rs/photon-rs/0.2.0/photon_rs/struct.PhotonImage.html#method.get_base64&quot;&gt;https://docs.rs/photon-rs/0.2.0/photon_rs/struct.PhotonImage.html#method.get_base64&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I don't know if node-fetch can be related to this&lt;/p&gt;
&lt;p&gt;I'm doing something wrong?&lt;/p&gt;
</description>
<category>ClojureScript</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9709/not-recognized-function-using-photon-library-with-node-js</guid>
<pubDate>Tue, 13 Oct 2020 05:02:28 +0000</pubDate>
</item>
<item>
<title>Compiling shadow-cljs projects with NPM transitive dependency conflicts</title>
<link>https://ask.clojure.org/index.php/8665/compiling-shadow-projects-transitive-dependency-conflicts</link>
<description>&lt;p&gt;I am attempting to make use of the &lt;code&gt;react-bootstrap&lt;/code&gt; module by leveraging NPM support in &lt;code&gt;shadow-cljs&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;First I add &lt;code&gt;react-bootstrap&lt;/code&gt; and &lt;code&gt;bootstrap&lt;/code&gt; to &lt;code&gt;package.json&lt;/code&gt;:&lt;br&gt;
&lt;code&gt;$ yarn add react-bootstrap bootstrap&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;And then require &lt;code&gt;react-bootstrap&lt;/code&gt; in my project:&lt;br&gt;
&lt;code&gt;(ns myproject.core
  (:require [&quot;react-bootstrap&quot; :as bs]))&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The result is a runtime exception in the console:&lt;br&gt;
&lt;code&gt;TypeError: (0 , _uncontrollable.default) is not a function&lt;/code&gt;&lt;br&gt;
... which curiously goes away after the first hot-reload.&lt;/p&gt;
&lt;p&gt;The exception likely indicates a conflict in a nested NPM dependency. How can I identity and resolve the problem?&lt;/p&gt;
</description>
<category>ClojureScript</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/8665/compiling-shadow-projects-transitive-dependency-conflicts</guid>
<pubDate>Thu, 26 Sep 2019 18:08:41 +0000</pubDate>
</item>
</channel>
</rss>