Fork me on GitHub
#shadow-cljs
<
2018-12-11
>
idiomancy00:12:55

has anyone here successfully made a lambda function with shadow-cljs that calls the aws sdk?

royalaid01:12:20

Yes, I have I have not but I plan on working through it later this week

idiomancy08:12:10

@royalaid let me know when you do. there are a couple of gotchas I can help you with.

idiomancy08:12:18

I'm stuck on one of them now.

idiomancy08:12:45

When promesa is in the stack, I'm getting "cannot find module bluebird"

thheller10:12:17

this means you must install the bluebird npm package. no idea how to do that for AWS though.

idiomancy17:12:34

I just have to copy the node_modules into the target directory and zip the whole thing up before I send it up to lambda. shouldn't be a big deal. Thanks so much for that insight, that's really helpful

idiomancy08:12:56

when I try to invoke the lambda

pez08:12:07

@idiomancy I have seen some discussions about how mixing externs and shadow's built in ways to resolve them can cause problems. I have also just recently experienced that it sometimes matters what kind of target you are using. Looking at the promesa source code I see this: https://github.com/funcool/promesa/blob/547d01652f335df18d4f2950efc8e7caba416fbb/assets/deps.cljs#L5 It might and might not be what is biting you. I guess one way to find out is to try build the promesa library yourself, using shadow-cljs.

idiomancy08:12:18

so, this experiment you're suggesting

idiomancy08:12:23

to build the promesa library

pez08:12:36

Suggesting is a strong word 😃

pez08:12:55

Maybe check what the Shadow User Guide says about externs first. Might be some way to configure around the problem you are seeing.

idiomancy08:12:16

the word externs is terrifying to me

pez08:12:25

But since it is in a cljs library you are using, I somehow doubt that there is an easy solution.

pez08:12:50

If you build promesa using shadow-cljs it will take care of externalizing stuff. What I had in mind was trying to just put the promesa code in your src path and let it be part of your build (as an experiment).

pez08:12:43

Full disclosure: I am a shadow-cljs noob (and Clojure(Script) noob as well). I am just trying to piece together whatever clues and hints I have picked up so far.

pez08:12:42

This looks interesting (from the user guide): > With :auto the compiler will perform additional checks at compile time for your files only. It won’t warn you about possible externs issues in library code. :all will enable it for everthing but be aware that you may get a lot of warnings.

pez08:12:20

(Regarding :compiler-options {:infer-externs)

idiomancy09:12:10

alright.. building with the bluebird assets in and compiler options set... lets giver er a whirl

idiomancy09:12:44

test unsuccessful. bluebird remains unfound 😞

pez09:12:14

😞 Did you use :all?

pez09:12:48

Also, probably best to clean the build.

thheller10:12:33

this is never necessary. if it is its a bug but so far I had no reports that there are any issues.

pez10:12:43

Ah, good to know. Should lower my build times a lot.

pez09:12:58

What optimizations are you using, btw?

idiomancy09:12:14

well, the :shadow js-provider purpotedly only uses simple optimizations

thheller10:12:18

externs have nothing to do with cannot fine module bluebird. thats just means the the npm package bluebird is not found by node. they are not bundled in node build (unlike browser builds)

pez10:12:53

That figures.

thheller10:12:01

externs only affect the renaming of JS code. so if you get weird errors like zy.Fp is not a function or undefined or whatever that is most likely caused by externs.

pez10:12:19

@thheller Do you have any idea what my ”Reference error clojure is not defined” could be about, when I use cljfmt in my npm-module build?

thheller10:12:05

had slack turned off over the weekend. which error?

pez10:12:48

When I build with target npm-module I seem to need to require things like clojure.string or I get this reference error. (I didn't need that with the node-library build.) That's not a problem, but it also seems to extend to libraries I use. So when cljfmt reaches certain paths in its code it croaks with the reference error of clojure not being defined.

thheller10:12:58

what is the full error? including stack trace.

thheller10:12:49

the code is bundled differently for :npm-module and is more sensitive to use-without-require type of code problems.

pez10:12:51

I don't get a stack trace. But I guess I could make that happen.

thheller10:12:12

so most likely something in cljfmt uses clojure.string (or something similar) but does not :require it in its ns

thheller10:12:42

thats my guess anyways. can't say more without stacktrace

pez10:12:03

That's what I think as well. Is there a way around it, if that is the case?

thheller10:12:17

yeah fix cljfmt (if thats indeed the error)

pez10:12:08

OK. I'll do that. Wasn't sure it was an error to use cljoure.string without requiring it.

thheller10:12:17

but can't say anything without a stacktrace

pez10:12:33

I also have this problem with regular expressions: https://clojurians.slack.com/archives/C6N245JGG/p1544256572353800

thheller10:12:32

hmm that is odd

thheller10:12:43

try :compiler-options {:output-charset "ASCII"} maybe?

thheller10:12:16

hmm no that is only for optimized builds

thheller10:12:35

> It works in a Figwheel browser project

thheller10:12:43

I'm guessing that it also works in a shadow-cljs browser project?

thheller10:12:54

eg. browser-repl?

thheller10:12:57

which node version is that?

pez10:12:00

Haven't tried it in a browser project. Let me check the node version.

pez10:12:06

I get 9.7.1 from node --version.

pez10:12:28

It works in browser-repl.

thheller10:12:04

node version seems fine. no idea whats happening.

thheller10:12:35

does it work when you use it in a file and not via the REPL?

pez10:12:17

Hmmm, let me try that

pez10:12:57

It doesn't work when used in my extension either.

thheller10:12:38

did you load it via the REPL?

thheller10:12:16

does it fail when you put it into a file that is loaded on startup regularly without a REPL even being attached?

pez10:12:10

I didn't have any repl attached when I tried now. Just built the extension with shadow's watcher and loaded it.

thheller10:12:50

can you try constructing the regexp differently?

pez11:12:06

Not sure how I would do that.

thheller11:12:07

(js/RegExp. "[\p{L}]+" "u")

pez11:12:31

It looks right to me. 😃

thheller11:12:39

(js/RegExp. "[\\p{L}]+" "u")

pez11:12:48

yes, of course

pez11:12:49

Then I get the error when constructing the regexp. (But it works in browser-repl)

thheller11:12:17

no idea sorry

thheller11:12:31

seems to work fine when you do it directly in node

pez11:12:06

not for me...

thheller11:12:36

in node. no cljs.

thheller11:12:11

$ node
> /[\p{L}]+/u
/[\p{L}]+/u
>

thheller11:12:15

does that not work for you?

pez11:12:26

No, I get ”invalid escape”. Very strange. I have the same on two of my computers. In any case it is now a shadow issue, which I thought at first.

pez11:12:48

I do have yet another issue though… I can't require my npm-module from an npm install. Only if I npm link it locally.

thheller11:12:52

no idea what that means

thheller11:12:25

be verbose in error reports. I can't guess anything with this little information.

pez12:12:18

I'm sorry. It is the whole problem. And not an error report, I think. It is rather me not being able to figure out how to do it. To me it looks like I am doing what you showed me (`npm i @shadow-cljs/npm-module-demo` then require("@shadow-cljs/npm-module-demo")). In my case I do

const formatter = require('@cospaia/calva-lib/lib/calva.fmt.formatter'); 
But it does not work from an npm install only from an npm link.

thheller12:12:34

what error do you get though?

pez12:12:26

Let me reproduce it. (This was on my home computer a few days ago).

thheller12:12:09

always say what happens when something doesn't work. just saying "it does not work" is not very useful on its own.

pez12:12:26

Activating extension 'cospaia.calva-fmt' failed: Cannot find module '@cospaia/calva-lib/lib/calva.fmt.formatter'.

pez12:12:08

Again, if I npm link it locally, it works (as in no complaints) and the extension does what it should do (minus croaking on certain input due to that cljfmt thing that I need to fix).

thheller12:12:51

when you install it. does the file node_modules/@cospaia/calva-lib/lib/calva.fmt.formatter.js exist?

thheller12:12:12

you may just not package the files properly for npm when creating the actual package?

thheller12:12:31

npm link is just a symlink so it will contain files that may not the in the package otherwise

thheller12:12:44

eg. you are ignoring the lib/ directory?

pez12:12:01

What do you mean I am ignoring lib/? In some .ignore file?

thheller12:12:26

does the file exist or not?

pez12:12:27

You are right, I only have the main: file (from packages/package.json) there.

pez12:12:53

lib/calva.main.js in my case.

pez12:12:11

Great, then I need to figure out how to package this properly.

thheller12:12:20

maybe npm uses .gitignore when building the package

thheller12:12:44

IIRC it does if there is no .npmignore but can't remember

pez12:12:50

The .gitignore file in packages/ lists:

*.js
*.js.map

pez12:12:45

It's the same with your demo module (that it only contains the main: entry).

pez12:12:16

But I'll figure it out. Tons of thanks for all the help!

pez12:12:50

Yes, it works if I specify

"files": [
        "lib/"
    ]
in package.json. Yay!

javi13:12:16

I just upgraded to 2.7.8 and i am getting this warning when running a build with :bootstrap target

[2018-12-11 13:01:18.740 - WARNING] :shadow.cljs.devtools.server.util/handle-ex - {:msg {:type :start-autobuild}}
AssertionError Assert failed: (symbol? current-ns)
        shadow.build.cljs-hacks/shadow-js-access-global (cljs_hacks.cljc:16)
        shadow.build.cljs-hacks/shadow-js-access-global (cljs_hacks.cljc:16)
        shadow.build.cljs-hacks/shadow-resolve-var (cljs_hacks.cljc:167)
        shadow.build.cljs-hacks/shadow-resolve-var (cljs_hacks.cljc:131)
        shadow.build.cljs-hacks/shadow-resolve-var (cljs_hacks.cljc:135)
        shadow.build.cljs-hacks/shadow-resolve-var (cljs_hacks.cljc:131)
        cljs.analyzer/resolve-symbol/fn--2589 (analyzer.cljc:3910)
        cljs.analyzer/resolve-symbol (analyzer.cljc:3909)
        cljs.analyzer/resolve-symbol (analyzer.cljc:3905)
        clojure.tools.reader/syntax-quote* (reader.clj:705)
        clojure.tools.reader/syntax-quote* (reader.clj:693)
        clojure.tools.reader/expand-list (reader.clj:623)
any ideas of where i should start looking to get rid of it? thanks in advance..

thheller13:12:18

@fj.abanses in the shadow-cljs clj-repl try (def x (shadow/compile! :the-build-id {}))

thheller13:12:36

need the full stacktrace

thheller13:12:24

or if you have more of the above thats fine too

thheller13:12:33

just need to know where it is fully in the stack

thheller13:12:09

also if you are using deps/lein make you sure have the correct tools.reader version

thheller13:12:32

might be a dep conflict. never seen that error before.

Whiskas13:12:04

How is the experience for shadow-cljs users when integrating JSX modules into a CLJS project?

thheller13:12:44

JSX is not supported, so you need to run babel separately. but works ok-ish https://github.com/shadow-cljs/examples/tree/master/babel

javi13:12:15

hi @thheller it is on my side, an ns started complaining when compiled... nearly got the culprit 🙂 thanks, apologies for the noise!

Whiskas13:12:37

Is it easy to replace figwheel with shadow-cljs in a project generated by a leinegan template?

thheller13:12:07

well it doesn't matter what kind of project you have. you need to get familiar with shadow-cljs and how that works regardless. when you know how it works it is easy to switch the project yes.

Whiskas17:12:53

So… someone knows how to solve this?

Whiskas17:12:57

[:app] Configuring build.
-> build target: :browser stage: :configure
<- build target: :browser stage: :configure (2 ms)
[:app] Compiling ...
-> Analyzing Module: :app
[:app] Build failure:
The required namespace "day8.re-frame.tracing" is not available, it was required by "dbiz_health/commom/events.cljs".

Whiskas17:12:16

I could not find day8.re-frame.tracing in npm

jstaab17:12:23

And of course make sure re-frame is installed in your shadow-cljs.edn file.

Whiskas17:12:36

Oah, problem solved, i just forgot to migrate a dependency from the :dev profile to the main deps of shadow-cljs.edn

Whiskas17:12:01

------ WARNING #1 --------------------------------------------------------------
 File: bidi/bidi.cljc:29:12
--------------------------------------------------------------------------------
  26 | actually a valid UUID (this is handled by the route matching logic)."
  27 |   [s]
  28 |   #?(:clj (java.util.UUID/fromString s)
  29 |      :cljs (cljs.core.UUID. s)))
------------------^-------------------------------------------------------------
 Wrong number of args (1) passed to cljs.core.UUID
--------------------------------------------------------------------------------
  30 |
  31 | ;; When forming paths, parameters are encoded into the URI according to
  32 | ;; the parameter value type.
  33 |
--------------------------------------------------------------------------------
Someone knows how to solve this?

jstaab17:12:44

A number of things seem fishy to me there, try (cljs.core/uuid s)

jstaab17:12:47

Oh, I see that's in bidi

Whiskas17:12:57

yeah, i’m trying to compile and getting this error

Whiskas17:12:08

i found some issues about it on github, but no solution

jstaab17:12:16

outta my depth

Whiskas17:12:56

@morgancmartin Hey, can you share with me the fork you used to solve the bidi problem?

Whiskas19:12:35

Nvm, i just solved the problem by following this tutorial: https://stackoverflow.com/questions/17497937/patch-library-from-clojars

thheller20:12:28

@mateus.pimentel.w its just a warning also. no impact on runtime.