clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
ian_sinn 2020-09-04T10:08:53.243300Z

hello all, beginner question here. How do people go about authoring styles in cljs projects? Coming from JS-land I've enjoyed preprocessors and css-in-js. I'm doing some googling, but if anyone has recommendations I'd love to hear

ian_sinn 2020-09-04T10:39:36.243600Z

Thank you!

2020-09-04T12:35:53.250Z

Would the feedback on how similar one set of css styles was to another on your application be useful for people? I'm thinking something that reads any styles you have and provides you with a list of "very close" results. This could be used to Prevent style drift if the styles were supposed to be the same but weren't shared data

Daniils Petrovs 2020-09-04T13:37:07.253800Z

Hey all, a bit of non-standard question here: how do you usually use an HTTP client in ClojureScript with Node.js target? โ€˜Clojure-httpโ€™ isnโ€™t an option since it uses XMLHTTPRequest under the hood. Maybe someone has a decent example? Only need to make a simple POST with some qparams. ๐Ÿ™‡

Daniils Petrovs 2020-09-05T09:04:44.263500Z

Thank you, will give it a try

2020-09-05T09:49:24.263900Z

Maybe you can try to update your Shadow-cljs version and then rebuild.

2020-09-06T13:17:22.284800Z

@thedanpetrov So did you find the culprit?

athomasoriginal 2020-09-06T19:31:31.285200Z

If this hasnโ€™t been resolved, there is a video illustrating using axios: https://www.youtube.com/watch?v=0zaw3gcf0Sk

๐Ÿ‘ 1
Daniils Petrovs 2020-09-07T07:42:16.286100Z

Hmm haver tried with the way in your repo, still gives me the same error ๐Ÿ˜• Iโ€™ll check out the video too. Maybe I am building wrong? I use this script: shadow-cljs release :lambda --debug (same as the package.json I posted above)

2020-09-07T09:08:24.286400Z

The video is nice, however it uses Figwheel + the :bundle target of CLJS...I'm not sure that helps because with Shadow-CLJS it's different. Did you try updating your Shadow-cljs version and then rebuild a new release? Or did you try to run with shadow-cljs watch lambda and see if the error is still there?

Daniils Petrovs 2020-09-07T10:35:54.286600Z

itโ€™s already the latest shadow version, same one that you use in your example, so I donโ€™t think that is the issue here

2020-09-07T14:59:43.331800Z

Another suggestion, you can also tried to npx shadow-cljs build lambda to see if it works without production optimizations.

Daniils Petrovs 2020-09-07T15:21:03.332Z

Maybe you mean compile ? But in any case I get a strange error like this:

The required namespace "main.lambda" is not available, it was required by "shadow/umd_helper.cljs"
Even though my namespace is declared and the path is correct

2020-09-07T15:53:11.332200Z

Exactly, I was meaning compile. ๐Ÿ˜‰ When you do tree src/ , did you have the right path src/main/lambda.cljs ? Your lambda file extension is "cljs" not "clj"?

Daniils Petrovs 2020-09-07T16:12:11.332400Z

Yep, this is what tree looks like:

src
โ”œโ”€โ”€ main
โ”‚ย ย  โ””โ”€โ”€ lambda.cljs
โ””โ”€โ”€ test
    โ””โ”€โ”€ lambda-test.cljs

2020-09-07T17:29:26.332600Z

Hmm, strange...I see no other solution than to invoke the Shadow master! ๐Ÿ™‚ @thheller Do you have any clue about this error?

thheller 2020-09-07T17:30:44.332800Z

Cannot find module 'axios' this is the error in question right?

thheller 2020-09-07T17:34:29.333Z

the answer to that is simply that shadow-cljs does not bundle JS dependencies when running node. it is assumed that node will provide them at runtime which mean whereever you are running them the node_modules/axios needs to be available. if you want a self-contained JS file with no external dependencies post-process the file with something like https://github.com/vercel/ncc

2020-09-07T18:50:36.335900Z

Fine thank you @thheller, since the project is intended to run on aws Lambda, this must be the reason indeed. @thedanpetrov you confirm that you encounter these errors on Aws Lambda. Have you tried running it locally to see if it works? And then deploy with the bundle dependencies https://stackoverflow.com/a/48357506/5773724

Daniils Petrovs 2020-09-07T18:52:09.336200Z

Hmm I thought shadow-cljs bundles your npm dependencies for you, just like webpack? Or am I deceiving myself.

thheller 2020-09-07T19:00:25.336400Z

it does for browser builds yes. for node builds that is typically not needed or wanted

Daniils Petrovs 2020-09-07T19:20:32.337Z

I see, that explains a lot then :D thanks guys!

๐Ÿ‘ 1
Daniils Petrovs 2020-09-04T13:52:51.254Z

I have tried using interop and the axios library, but I get an import error:

(ns main.lambda
  (:require ["axios" :as axios]))

Daniils Petrovs 2020-09-04T13:52:58.254200Z

"Error: Cannot find module 'axios'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",

trinne7 2020-09-04T14:42:30.254400Z

Iโ€™ve used this in my current project https://github.com/Jarzka/stylefy

๐Ÿ‘ 1
2020-09-04T15:18:44.255200Z

Hi @thedanpetrov How do you run ClojureScript ? Shadow-CLJS, Figwheel or vanilla CLJS ?

Daniils Petrovs 2020-09-04T15:18:58.255400Z

Hey, shadow

Daniils Petrovs 2020-09-04T15:19:33.255600Z

my shadow-cljs.edn looks something like this:

{
 :lein false

 :source-paths ["src"]
 :dependencies
 []

 :builds
 {:lambda {:target :node-library
           :output-to "./dist/lambda/index.js"
           :exports {:handler main.lambda/handler}
           :compiler-options {:infer-externs :auto}
           }
  :node {:target :node-script
         :output-to "./dist/node/index.js"
         :main main.lambda/start
         :devtools {:after-load main.lambda/reload}}
  :test {:target :node-test
         :output-to "./build/test.js"}
  }}

2020-09-04T15:38:44.255800Z

It works for me. And your package.json file?

Daniils Petrovs 2020-09-04T16:14:37.256Z

{
  "name": "yuno",
  "description": "",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "shadow-cljs": "2.10.19"
  },
  "dependencies": {
    "axios": "^0.20.0"
  },
  "scripts": {
    "build": "shadow-cljs release :lambda --debug",
    "predeploy": "npm run build",
    "deploy": "cd dist/lambda &amp;&amp; zip lambda.zip index.js &amp;&amp; aws lambda update-function-code --profile cvi-aws-admin --function-name yuno --zip-file <fileb://lambda.zip>",
    "clean": "rm -rf dist"
  }
}

Daniils Petrovs 2020-09-04T16:14:47.256200Z

I donโ€™t think too much out of the ordinary here

ian_sinn 2020-09-04T16:24:22.256500Z

Thanks. This Garden projects seems to be quite popular seeing as it's used by multiple two of these other projects

Mark Gerard 2020-09-04T17:47:51.257500Z

This is a very strange warning, anyone have a clue to what it means: > WARNING: The org.clojure/core.async dependency in shadow-cljs.edn was ignored. Default version is used and override is not allowed to ensure compatibility.

Karol Wรณjcik 2020-09-04T18:33:46.258600Z

@cattabanks it means that you should not include core.async in dependencies for shadow-cljs

Mark Gerard 2020-09-04T18:44:00.258900Z

Any reason why?

thheller 2020-09-04T19:21:11.259600Z

things break badly when using an incompatible core.async version since shadow-cljs uses core.async directly itself

thheller 2020-09-04T19:21:25.259800Z

so core.async is always available

๐Ÿ‘ 1
Mark Gerard 2020-09-04T19:22:24.260300Z

Got you

2020-09-04T21:51:42.261Z

I made a simple repo who works perfect for me, maybe it can help: https://github.com/PrestanceDesign/cljs-node-axios

๐Ÿ‘ 1