Fork me on GitHub
#clojurescript
<
2018-06-26
>
souenzzo01:06:55

Hello I'm trying to implement the "webpack method" on my "real" project but the compiler says Error: Cannot find module '@cljs-oss/module-deps' On a small/toy project, I do exactly the same and get no errors.

souenzzo02:06:28

Figwheel: Starting server at 
Figwheel: Watching build - dev
Compiling build :dev to "resources/public/javascript/main.js" from ["src" "test" "dev"]...
internal/modules/cjs/loader.js:596
    throw err;
    ^

Error: Cannot find module '@cljs-oss/module-deps'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
    at Function.Module._load (internal/modules/cjs/loader.js:520:25)
    at Module.require (internal/modules/cjs/loader.js:650:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at [eval]:8:13
    at Script.runInThisContext (vm.js:91:20)
    at Object.runInThisContext (vm.js:298:38)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
    at evalScript (internal/bootstrap/node.js:531:27)

Successfully compiled build :dev to "resources/public/javascript/main.js" in 8.408 seconds.

souenzzo03:06:39

happens when #reagent tryes to require react-dom

(require '[react-dom :as rdom])
internal/modules/cjs/loader.js:596
    throw err;
    ^

Error: Cannot find module '@cljs-oss/module-deps'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
    at Function.Module._load (internal/modules/cjs/loader.js:520:25)
    at Module.require (internal/modules/cjs/loader.js:650:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at [eval]:8:13
    at Script.runInThisContext (vm.js:91:20)
    at Object.runInThisContext (vm.js:298:38)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
    at evalScript (internal/bootstrap/node.js:531:27)
My compiler
:infer-externs   true
:install-deps    false
:foreign-libs    [{:file           "dist/index_bundle.js"
                   :provides       ["react" "react-dom" "material-ui" "react-bootstrap"]
                   :global-exports {react           React
                                    react-bootstrap ReactBootstrap
                                    material-ui     MaterialUI
                                    react-dom       ReactDOM}}]
and my index.js
import React from 'react';
import ReactDOM from 'react-dom';
import * as MaterialUI from '@material-ui/core/index.js';
import * as ReactBootstrap from 'react-bootstrap';

window.React = React;
window.ReactDOM = ReactDOM;
window.MaterialUI = MaterialUI
window.ReactBootstrap = ReactBootstrap

souenzzo03:06:39

happens when #reagent tryes to require react-dom

(require '[react-dom :as rdom])
internal/modules/cjs/loader.js:596
    throw err;
    ^

Error: Cannot find module '@cljs-oss/module-deps'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
    at Function.Module._load (internal/modules/cjs/loader.js:520:25)
    at Module.require (internal/modules/cjs/loader.js:650:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at [eval]:8:13
    at Script.runInThisContext (vm.js:91:20)
    at Object.runInThisContext (vm.js:298:38)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
    at evalScript (internal/bootstrap/node.js:531:27)
My compiler
:infer-externs   true
:install-deps    false
:foreign-libs    [{:file           "dist/index_bundle.js"
                   :provides       ["react" "react-dom" "material-ui" "react-bootstrap"]
                   :global-exports {react           React
                                    react-bootstrap ReactBootstrap
                                    material-ui     MaterialUI
                                    react-dom       ReactDOM}}]
and my index.js
import React from 'react';
import ReactDOM from 'react-dom';
import * as MaterialUI from '@material-ui/core/index.js';
import * as ReactBootstrap from 'react-bootstrap';

window.React = React;
window.ReactDOM = ReactDOM;
window.MaterialUI = MaterialUI
window.ReactBootstrap = ReactBootstrap

vigilancetech05:06:11

how do I suppress stack traces in the repl (cider)?

juhoteperi05:06:25

@souenzzo Looks like you have node_modules directory present, disable npm module support with :npm-deps false option

👍 4
juhoteperi05:06:53

:install-deps option is no-op without :npm-deps

souenzzo12:06:24

just bumped figwheel from .15 to .16 to recognize this option Tnks!

nik07:06:47

Hi guys, may I ask a very abstract question: is it possible (or is it worth it?) to use Clojurescript+ReactNative for business logic only? I'm fine with UI in Swift/Java, but I'd like to make a "core" engine which would handle HTTP calls, validation, forms handling, search, etc. I'm not really interested in x-platform UI as I have 100% positive experience with native technologies - I depend on pretty and fast native animations and other platform-dependent stuff - but I'm looking for a replacement for my current x-platform stack (C++ core/business logic/view models, djinni x-language bridging, Swift/Objective-C/Java/Kotlin for UI and platform-dependent code). So is it possible to make a small core in Clojurescript and then just execute callbacks on a native side which would consume nothing but maps and lists? Without touching ReactiveNative UI part. I'm eager to throw away C++ from my life 😬

Roman Liutikov08:06:37

Maybe you don’t even need RN then at all! You could just load the code into JSCore engine. But then you would probably need to setup bridge and everything by yourself, so perhaps RN would be a better “platform” for your needs.

❤️ 4
mfikes12:06:24

That's what I did with Goby https://github.com/mfikes/goby

👍 4
mfikes12:06:45

(Before React Native was available.)

nik12:06:42

@mfikes I've already seen this repo which means you're famous! 🙂

martinklepsch12:06:24

Is metadata on namespaces allowed/supported in some way?

thheller12:06:09

@martinklepsch allowed and supported yes (but as usual only available in analyzer data in the compiler env)

martinklepsch12:06:52

@thheller just to be sure, this syntax and all (ns ^:no-doc codox.example3), should be reflected in the result of parse-ns?

thheller12:06:39

uhm actually I'm not sure if it works properly in CLJS. I vaguely remember fixing a related issue in shadow-cljs, not sure if I ever made a ticket/patch for this

thheller12:06:44

but yes that is valid

thheller12:06:59

(ns codox.example3 {:no-doc true}) would also be correct

martinklepsch12:06:40

@thheller hm, I can’t get it to work at all 😅 does any of this look wrong to you?

thheller12:06:59

hmm CLJS might not store the data in the AST properly

thheller12:06:16

only on the (-> ast :name meta)

thheller12:06:48

this will get lost with caching enabled though

martinklepsch13:06:16

@thheller thanks (-> ast :name meta) was it! not sure I would have thought of trying that 🙌 🙂

👍 4
scknkkrer13:06:44

Guys, I am using Webpack to pack external libraries and calling them from js namespace from clojurescript. But I can’t optimize my code because of that.

scknkkrer13:06:58

Any solution for this ?

thheller13:06:59

why can't you optimize?

Yehonathan Sharvit13:06:50

Hi there, Anyone knows a good library (or safe piece of code) that exposes a cljs function that returns a core.async channel for javascript consumption?

scknkkrer13:06:52

@thheller, hi again. 😇 It was an early crying. I solve my problem with these steps: - I looked into Optimization Documentation. It Cryptes variable names. --I didn’t know, really ¯\(ツ)/¯ - I thought, If I change my variables into strings. --which is crytical/untouchable for optimization processor. - I change my variable accessing function with goog.object/getValuesByKeys function call. It solved my problem. I don’t think it would be that easy. My verbosity for newbies like me. —forgive me guys—

scknkkrer13:06:26

@thheller do you have any other solution for this. I don’t know, it is the right way or not…

jjttjj14:06:48

does array-seq result in a lazy seq?

jjttjj14:06:06

I'm getting (instance? LazySeq (array-seq #js[1 2 3])) => false so that means it's not lazy right?

mfikes14:06:47

@jjttjj Right. It returns a cljs.core/IndexedSeq, which can do nth, for example, in O (1).

mfikes14:06:40

(indexed? (array-seq #js [1 2 3])) => true

thheller16:06:07

@scknkkrer you might be looking for (defn ^:export your-fn [] ...) if you mean to call your.app.your_fn() from HTML?

whilo20:06:14

Entering 1/2 in a figwheel REPL and with "lein cljsbuild once" I get: "failed compiling constant: 1/2; class clojure.lang.Ratio is not a valid ClojureScript constant." lumo is dealing with it just fine returning a float for cljs.

whilo20:06:25

In another project I get "No method in multimethod 'emit-constant' for dispatch value: class clojure.lang.Ratio"

whilo20:06:00

unfortunately a quick web search has not revealed what is exactly the status of ratios.

anmonteiro20:06:04

@whilo I’m not sure ClojureScript supports ratios

whilo20:06:11

it doesn't

whilo20:06:25

but it should be able to read expressions like this, i think

anmonteiro20:06:35

the reason it works in Lumo is because the underlying compiler platform is JavaScript

whilo20:06:01

yes, it seems the cljs reader can deal with ratios just fine

anmonteiro20:06:07

and JavaScript just accepts the 1/2 pattern and a bunch of other garbage

whilo20:06:18

but shouldn't the cljs reader throw an error at me?

anmonteiro20:06:42

@whilo I think the reader reads it just fine

anmonteiro20:06:57

the error you’re getting is from the ClojureScript emitter if I’m not mistaken

whilo20:06:36

yes, isn't that a bit weird?

anmonteiro20:06:43

^ do you know if there’s an open JIRA for this?

dnolen20:06:47

well whether it should work is really up for discussion

dnolen20:06:58

just because the reader passes it through isn’t a reason

dnolen20:06:17

coercing to another numeric type isn’t desirable IMO

dnolen21:06:15

@whilo so you’re just asking for a more meaningful error like "ratios aren't supported"

mfikes21:06:36

A motivating similar example. Consider .3 That is not a valid thing in Clojure. The fact that it seems to do something in ClojureScript doesn't mean it is valid in ClojureScript.

mfikes21:06:52

(All I'm sayin is that there are things you can type which have undefined behavior.)

whilo21:06:54

@dnolen that is an option. i have just been confused by porting some clojure tests and 4/2 was working, while 1/3 stayed a ratio and was throwing the error at me

whilo21:06:38

if 1/4 is supposed to be syntax for ratios and they are not supported then it should probably not be readable

whilo21:06:56

if 1/4 is a valid shorthand for 0.25, then it should be autocasted

dnolen21:06:15

well I don’t really agree with either of those conclusions 🙂

whilo21:06:25

perfect 🙂

dnolen21:06:36

whether it’s readable or not is not that relevant I think

dnolen21:06:37

reading is more than source

dnolen21:06:17

autocasting is not really a thing in Clojure

dnolen21:06:37

far as I tell this is just about the error message

whilo21:06:46

what does 1/4 mean?

dnolen21:06:11

what does it mean in Clojure?

dnolen21:06:32

then that’s what it should mean in ClojureScript

whilo21:06:39

there it is describing a rational number and equivalent to (/ 1 4), right?

dnolen21:06:46

unless … we cannot provide generic arithmetic

dnolen21:06:51

which we can’t yet

dnolen21:06:05

not without damaging performance across the board

whilo21:06:19

you mean polymorphic arithmetic?

whilo21:06:22

what would be the interesting types in cljs? big numbers and ratios? or full protocol support like core.matrix(?)

whilo21:06:42

i am atm. working with core.matrix in cljs

mfikes21:06:46

Actual 64-bit integers would be interesting as well 🙂

whilo21:06:07

what is happening in js land in this direction?

dnolen21:06:19

there’s a multimethod proposal which far as I know hasn’t gone anywhere

whilo21:06:36

hmm, how can this not be a perf problem in js? clojure piggiebacks on java's polymorphic method dispatch, right?

dnolen21:06:03

JS only has one numeric type - Double

dnolen21:06:52

JS engines however play lots of tricks due to the spec

whilo21:06:04

yes, but i guess some people would like to support richer numerical types

dnolen21:06:06

to optimize to 32bit integer math when they can

whilo21:06:41

just for reference, i am porting https://probprog.github.io/anglican/ to cljs atm.

😎 4
🎉 4
mfikes21:06:45

I've played with https://github.com/gfredericks/exact a bit. It can be tedious, but is definitely useful

dnolen21:06:54

@whilo anyways - in case somehow something was misunderstood 1/4 is a valid literal in Clojure

dnolen21:06:35

it can’t be yet in ClojureScript - due to the issues I’ve mentioned

mfikes21:06:54

FWIW, https://dev.clojure.org/jira/browse/CLJS-555 is one of the most highly voted JIRAs

whilo21:06:03

i agree and it is not critical for me, i have moved to the (/ 1 4) expressions

whilo21:06:11

ratio support itself is helpful, because of floating point numerical errors. it makes testing of some code easier and precise

whilo21:06:57

i am now getting (not (m/equals [10.666666666666666 10.666666666666666 10.666666666666666 10.666666666666666] [10.666666666666664 10.666666666666664 10.666666666666664 10.666666666666664]))

whilo21:06:01

for example

whilo21:06:19

which means i need to use different equality semantics with an epsilon

mfikes21:06:54

You also have the unfortunate difference with (/ 0) between Clojure and ClojureScript. Former is an error, latter is a hosty mathematical ¯\(ツ)/

justinlee21:06:23

presumably it’d be very hard to add different forms of math to + without incurring a dynamic dispatch overhead on all mathy things

justinlee21:06:42

(my favorite javascriptism is (+ .1 .2))

mfikes21:06:13

If you're so inclined, -0.0 will bother you endlessly 🙂

justinlee21:06:27

omg. and it keeps track of the signs if you keep multiplying -0 times itself. haha.

mfikes21:06:48

It exists, you just can't print it. Behold: (/ (/ ##-Inf))

justinlee21:06:57

oh i see. i didn’t know about that in javascript to being with and now that i’ve learned of it i now learn it won’t print in clojurescript. 🙂

Garrett Hopper21:06:53

Are shadow-cljs and cljs.main comparable to each other?

bhauman22:06:08

@ghopper they are different, if you have been using cljs.main I'd suggest you try figwheel.main as the cli is comparable

Garrett Hopper22:06:34

I've actually been using cljs.main. I was just wondering if they were on the same level.

bhauman22:06:42

but shadow and figwheel.main are both more fully featured

Garrett Hopper22:06:44

Err, I've been using figwheel.main.

Garrett Hopper22:06:04

Ok, so shadow-cljs would be comparable to figwheel.main?

bhauman22:06:23

yes, it has a different compiling strategy

Garrett Hopper22:06:35

I just figured I'd try all the options before settling on something. I started with Boot-cljs, then I tried pure cljs.main, then I moved on to your figwheel.main.

Garrett Hopper22:06:47

It uses the normal cljs compiler under the hood though, right?

bhauman22:06:09

yes, AFAIK

Garrett Hopper22:06:14

:thumbsup: Thanks

Garrett Hopper22:06:37

I'm still not sure I buy into this CLI script with Makefile idea. It's certainly very nice for some things during development, but there's a lot to be said for the build process entirely being a clj program.

bhauman22:06:31

@ghopper and there is nothing preventing that

bhauman22:06:20

you can trigger your build process from code in a very straightforward way

Garrett Hopper22:06:20

You make a fair point. I think I just need to spend more time to figure out where the happy middle ground is between using CLI argument only and calling the clj API instead.

Garrett Hopper22:06:37

I kinda jumped from one extreme to the other.

bhauman22:06:03

so you are aware that you can add main options to deps.edn?

Garrett Hopper22:06:36

Hmm, no, I'm not actually sure what that does.

Garrett Hopper22:06:52

I know I can just write build scripts and clj $script them.

bhauman22:06:40

you can create aliases that invoke command line args

bhauman22:06:11

and you can invoke that alias clj -A:build

Garrett Hopper22:06:16

Oh, right, yeah. I thought you were saying there was a :main entry in deps.edn that did something. I'm familiar with aliases. That's a good idea over just doing everything in the Makefile.

Garrett Hopper22:06:34

I've only used them for my system global aliases for rebel readline and such.

Garrett Hopper22:06:25

I do like that over all the phony tasks I have in my Makefile.

bhauman22:06:58

an interesting pattern is to have a user.clj file with a bunch of tasks in it and then invoke functions in it via these aliases

Garrett Hopper22:06:27

Do you by any chance have a repo you can point to that's using this?

bhauman22:06:34

{:main-opts ["-e" "(user/build)"]}

bhauman22:06:50

I'm sorry I don't

Garrett Hopper22:06:09

It's a good idea. I was thinking I'd need separate namespaces for each to use -m.

Garrett Hopper22:06:16

That's alright :thumbsup:

Garrett Hopper22:06:00

I know this is kinda new ground. Overall I'm liking the direction. It feels a lot cleaner without the overhead of Boot's abstractions.

Garrett Hopper22:06:15

(or Leiningen for that matter)

bhauman22:06:31

way less magic, but you better get the classpath right 🙂

Garrett Hopper22:06:02

🙂 Thanks for talking through things with me.

bhauman22:06:40

you would want to separate namespaces if you had a vastly different set of dependencies for certain tasks

Garrett Hopper22:06:12

Yeah, certainly. So if you had for e.g. tasks for managing AWS infrastructure via CloudFormation, would you do that in a Makefile, or would it make sense to use clojure.java.shell to call the aws CLI?

Garrett Hopper22:06:30

That's kinda outside the scope cljs, I guess. I'm just trying to figure out how to divide things.

bhauman22:06:06

it really depends right?

bhauman22:06:29

is it a simple single call? is your team only on unix?

bhauman22:06:49

should you be using a java AWS api?

Garrett Hopper22:06:30

All good point. I hadn't thought about non Unix contributors. That is one of the benefits of using Boot and clj only stuff.

bhauman22:06:14

I think there is a clojure aws wrapper

Garrett Hopper22:06:28

There's a number of AWS calls, and I hadn't really considered using a Java API. I guess if we're sticking with the CLI it should be through the Makefile.

Garrett Hopper22:06:45

Yeah, there is. It's quite nice, though the CLI does a lot for you that I don't want to do manually.

bhauman22:06:19

perhaps better to start simple then

Garrett Hopper22:06:47

Right, and the CLI through a Makefile is simpler than trying to shell out from clj I think.

bhauman22:06:57

absolutely

bhauman22:06:26

gotta go make some dinner 🙂

Garrett Hopper22:06:34

Of course 🙂 Thanks again

👍 4