Fork me on GitHub
#clojurescript
<
2020-09-04
>
ian_sinn10:09:53

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

trinne714:09:30

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

👍 3
ian_sinn16:09:22

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

Drew Verlee12:09:53

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 Petrovs13:09:07

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 Petrovs13:09:51

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

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

Daniils Petrovs13:09:58

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

Michaël Salihi15:09:44

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

Daniils Petrovs15:09:33

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"}
  }}

Michaël Salihi15:09:44

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

Daniils Petrovs16:09:37

{
  "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 && zip lambda.zip index.js && aws lambda update-function-code --profile cvi-aws-admin --function-name yuno --zip-file ",
    "clean": "rm -rf dist"
  }
}

Daniils Petrovs16:09:47

I don’t think too much out of the ordinary here

Michaël Salihi21:09:42

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

👍 3
Daniils Petrovs09:09:44

Thank you, will give it a try

Michaël Salihi09:09:24

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

Michaël Salihi13:09:22

@U013SKZJM39 So did you find the culprit?

athomasoriginal19:09:31

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

👍 3
Daniils Petrovs07:09:16

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)

Michaël Salihi09:09:24

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 Petrovs10:09:54

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

Michaël Salihi14:09:43

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

Daniils Petrovs15:09:03

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

Michaël Salihi15:09:11

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 Petrovs16:09:11

Yep, this is what tree looks like:

src
├── main
│   └── lambda.cljs
└── test
    └── lambda-test.cljs

Michaël Salihi17:09:26

Hmm, strange...I see no other solution than to invoke the Shadow master! 🙂 @U05224H0W Do you have any clue about this error?

thheller17:09:44

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

thheller17:09:29

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

Michaël Salihi18:09:36

Fine thank you @U05224H0W, since the project is intended to run on aws Lambda, this must be the reason indeed. @U013SKZJM39 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 Petrovs18:09:09

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

thheller19:09:25

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

Daniils Petrovs19:09:32

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

👍 3
Mark Gerard17:09:51

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ójcik18:09:46

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

Mark Gerard18:09:00

Any reason why?

thheller19:09:11

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

thheller19:09:25

so core.async is always available

👍 3