This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-19
Channels
- # adventofcode (1)
- # announcements (3)
- # babashka (60)
- # beginners (60)
- # calva (5)
- # clj-commons (17)
- # clj-kondo (33)
- # clj-on-windows (1)
- # clojure (40)
- # clojure-austin (3)
- # clojure-europe (19)
- # clojure-gamedev (25)
- # clojure-nl (1)
- # clojure-norway (6)
- # clojure-sweden (4)
- # clojure-uk (2)
- # clojurescript (27)
- # conjure (1)
- # core-async (1)
- # core-typed (7)
- # cursive (5)
- # datomic (35)
- # events (1)
- # fulcro (35)
- # integrant (7)
- # introduce-yourself (2)
- # kaocha (5)
- # leiningen (2)
- # lsp (26)
- # malli (13)
- # nbb (99)
- # off-topic (15)
- # pathom (12)
- # pedestal (5)
- # polylith (8)
- # portal (4)
- # rdf (19)
- # reagent (8)
- # reitit (5)
- # releases (2)
- # remote-jobs (2)
- # rewrite-clj (1)
- # shadow-cljs (94)
- # testing (2)
- # timbre (2)
- # tools-deps (16)
Hi, How to use npm modules correctly in clojurescript for the below code
import axios from 'axios';
import { aws4Interceptor } from "aws4-axios";
const client = axios.create({ baseURL: BASE_UEL, headers: {appkey: 'test'}});
client.interceptors.request.use(aws4Interceptor({
region: AWS_REGION,
service: "execute-api",
},
{
accessKeyId: AWS_ACCESS_KEY_ID,
secretAccessKey: AWS_SECRET_ACCESS_KEY,
}
));
(PATH, JSON.stringify(body))
If you're using shadow-cljs, it's documented here: https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages
Thanks @U2FRKM4TW for you quick response. I use shadow-js and could able to import. But on runtime getting issues such as
TypeError: Cannot read property 'url' of undefined
Here is my code
["axios" :as axios]
["aws4-axios" :refer [aws4Interceptor]]
...
(p/let [instance (->
(axios/create
{:baseURL js/process.env.BASE_URL
:headers {:appkey (:key event)}}))
interseptor (aws4Interceptor
{:region js/process.env.AWS_REGION
:service 'execute-api'}
{:accessKeyId js/process.env.AWS_ACCESS_KEY_ID
:secretAccessKey js/process.env.AWS_SECRET_ACCESS_KEY})]
(.use (.. instance -interceptors -request) (interseptor))
)
> Cannot read property url
Your code doesn't mention the url
property anywhere. Can you provide a full stack trace of that error?
Also, note that you still have to pass JS objects to JS functions that expect them - you can't just shove CLJS data in there.
Meaning, all those {...}
you pass to axios functions should actually be #js {...}
. Including the nested ones, because #js
is shallow.
Now I am passing js objects. The error stack is
> (node:50334) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'url' of undefined
> at /Users/rambabupatina/sde/development/app-folder/functions/node_modules/aws4-axios/dist/interceptor.js:93:33
> at step (/Users/rambabupatina/sde/development/app-folder/functions/node_modules/aws4-axios/dist/interceptor.js:33:23)
> at Object.next (/Users/rambabupatina/sde/development/app-folder/functions/node_modules/aws4-axios/dist/interceptor.js:14:53)
> at /Users/rambabupatina/sde/development/app-folder/functions/node_modules/aws4-axios/dist/interceptor.js:8:71
> at new Promise (<anonymous>)
> at __awaiter (/Users/rambabupatina/sde/development/app-folder/functions/node_modules/aws4-axios/dist/interceptor.js:4:12)
> at /Users/rambabupatina/sde/development/app-folder/functions/node_modules/aws4-axios/dist/interceptor.js:88:39
> at $server$utils$register_with_ac [as register_with_ac] (/Users/rambabupatina/sde/development/app-folder/.shadow-cljs/builds/functions/dev/out/cljs-runtime/app/server/utils.cljs:48:49)
> at switch__40487__auto__ (/Users/rambabupatina/sde/development/app-folder/.shadow-cljs/builds/functions/dev/out/cljs-runtime/app/server/installations.cljs:42:11)
> at /Users/rambabupatina/sde/development/app-folder/.shadow-cljs/builds/functions/dev/out/cljs-runtime/app/server/installations.cljs:42:11
The line
(.use (.. instance -interceptors -request) (interseptor))
Changing to
(.use (.. instance -interceptors -request) interseptor)
resolved that issue. Thanks for narrowing down the issue.
But now I got another issue now
> (node:53573) UnhandledPromiseRejectionWarning: Error: No URL present in request config, unable to sign request
> at /Users/rambabupatina/sde/development/app-folder/functions/node_modules/aws4-axios/dist/interceptor.js:94:31
> at step (/Users/rambabupatina/sde/development/app-folder/functions/node_modules/aws4-axios/dist/interceptor.js:33:23)
> at Object.next (/Users/rambabupatina/sde/development/app-folder/functions/node_modules/aws4-axios/dist/interceptor.js:14:53)
> at /Users/rambabupatina/sde/development/app-folder/functions/node_modules/aws4-axios/dist/interceptor.js:8:71
> at new Promise (<anonymous>)
> at __awaiter (/Users/rambabupatina/sde/development/app-folder/functions/node_modules/aws4-axios/dist/interceptor.js:4:12)
> at /Users/rambabupatina/sde/development/app-folder/functions/node_modules/aws4-axios/dist/interceptor.js:88:39
> at processTicksAndRejections (internal/process/task_queues.js:95:5)
> (Use `node --trace-warnings ...` to show where the warning was created)
Though I am passing url
> Changing to [...] resolved that issue. Nice! > But now I got another issue As you can imagine, debugging someone else's code via a text chat is a logistical nightmare. :) NodeJS has debugging capabilities. Just add a breakpoint in that place, relaunch the app in the debugging mode, and poke around.
In ns1 I have (def ^:dynamic sentinel true)
and in ns2 I use (binding [ns1/sentinel false] ...)
where the body inside the binding calls promises. The binding isn't effective when functions inside the promise run. Doesn't seem to work with-redefs
either. Am I missing some magic?
no difference on the the JVM. clojure has bound-fn
to carry over bindings, cljs does not
The bit-count
function only works with integer-ish numbers with 32 bits or less, but since JS numbers are doubles that means you get ~51 bits of integer precision, and that means that bit-count
is poorly-behaved on large integer-ish numbers.
Is this something that was explicitly considered? With bit-count
being a cljs-only function I'd think that it would be designed specifically for JS types, but it appears to be designed with C integers in mind since that's where the algorithm used is most often defined.
As you might expect, I think there's a little more to the story, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number#fixed-width_number_conversion
The https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators#binary_bitwise_operators will treat numbers as a set of 32 bits.
Makes sense! That's the answer I was looking for
I'm trying to migrate from cljsbuild to shadow-cljs I can't find where is the "main" function/namespace in cljsbuild. And I have no idea which namespace is the main one.
the "main" namespace is the namespace where your code "initializes", basically where code runs when the JS is loaded
it is a big codebase.
In some cljsbuild configs, there is a :main
function. In others, it does not exists.
I can't understand how cljsbuild works without a main