Fork me on GitHub
#shadow-cljs
<
2020-02-06
>
dima11:02:27

Hello, :js-options :resolve currently isn’t supported when building for react-native target - is there a reason it’s not supported?

thheller13:02:51

@trybeee for react-native builds metro will be responsible for resolving packages. so you need to configure it there.

dima14:02:49

In deps.edn i have reagent dependency which excludes cljsjs/react dependency. During the build, shadow compiler fails with “react dependency is missing” so i’d like to resolve it with :js-options {:resolve {"react" {:target :global :global "React"}} as i’m adding react.js to the page via another script

thheller16:02:39

you said react-native? there are no pages? I'm unclear what you are doing?

thheller16:02:25

it complains about react missing only if the lib you used did (:require [react ...]) so not (:require ["react" ...])

thheller16:02:03

basically all you need is a node_modules folder that includes react

thheller16:02:16

a :react-native build won't actually use it .. but it will make the error go away

dima21:02:30

Sorry for confusion, you’re right there is no pages in RN, i was talking about browser target. We have multiple targets in out config. For react-native target, we still want shadow to pull js dependency code from external file, similar to what cljs compiler option :foreign-libs does https://cljs.github.io/api/compiler-options/foreign-libs Also, library doing (:require [react]) is reagent as it depends on cljsjs/react (not react from node_modules).

thheller21:02:55

(:require [react]) works fine in shadow-cljs IF node_modules/react exists

thheller21:02:40

I still don't get what your actual problem is though

thheller21:02:07

you have a browser build that uses :js-resolve to pick react from a global, coming from somewhere else

thheller21:02:24

and your react-native build fails because it can't find react?

thheller21:02:06

so what shadow-cljs does if you have (:require [react]) it'll first check if thats a regular CLJS namespace

thheller21:02:15

if that does not exist it'll look for node_modules/react

thheller21:02:22

if that does not exist it'll fail

thheller21:02:46

if you have it installed somewhere else (which I assume if you use react-native you can use :js-package-dirs

dima13:02:30

Thanks for pointing to :js-package-dirs option, it looks like that what i want. I basically want to point to the dir where to get “react” dependency from when building for react-native

sichacvah13:02:28

Hello! Somebody know how to configure tests in react native? Because if I try to start any test with react native component it fails with syntax error in warnOnce.js file

thheller13:02:08

how did you compile the tests?

sichacvah14:02:42

I tried as node-test or react-native

thheller14:02:09

things need to be compiled by react-native/metro

thheller14:02:32

I can't tell you how testing works in RN but you are likely going to need to use whatever they provide

sichacvah14:02:46

When I try to run with just (default test framework for react native) I faced ‘goof is not defined’ error.

thheller14:02:33

people in #cljsrn might know more. I don't use react-native myself so I can't help much

vikeri13:02:42

Hi! I suspect that my production build in electron uses the dev version of React. I’m using re-frame and reagent and I have react och react-dom in my package.json. Does anyone know how I can tell which build is used. shadow-cljs is still quite new to me.

thheller13:02:06

@vikeri which :target did you use?

vikeri13:02:20

(But I’m using electron)

thheller13:02:45

then create a build-report for your :browser build via https://shadow-cljs.github.io/docs/UsersGuide.html#_build_report

thheller13:02:53

it'll tell you exactly what it used

thheller13:02:12

(unless you configured :js-provider :require in which case it is all electron providing the dependencies)

vikeri13:02:37

I did configure :js-provider :require

thheller13:02:58

then shadow-cljs is out of the picture as far as dependencies are concerned

thheller13:02:24

electron might have a setting for process.env.NODE_ENV but I'm not sure how you'd set it

vikeri13:02:02

Ok thanks! I’ll look into it

vikeri13:02:43

Huge kudos for making shadow-cljs such a great experience to use! 👏

👍 24
dottedmag22:02:37

How do I use plain JS file with shadow-cljs that declares a global variable at the top? I required it (using an absolute path), but that does not cause this variable to be available via js/Var — is this expected? Is there a better way?

dottedmag22:02:51

(as an aside - maybe someone has made @octocat/rest work from NPM? it seems to depend on a Node-only package, but somehow authors also produce a release for Web without this dependency)

thheller22:02:40

@dottedmag declaring it in a file does not make it global. why does it need to be a global though?

dottedmag22:02:31

You can see it's var Octokit = ...; — no AMD, not a ES6 package, so I'm at loss how to use it except <script> in HTML and use the global.

thheller22:02:02

why are you looking at that file?

thheller22:02:22

npm install @octokit/rest and (:require ["@octokit/rest" :as x]) what does that give you?

dottedmag22:02:02

It gives me The required JS dependency "os" is not available, it was required by "node_modules/os-name/index.js"

dottedmag22:02:20

"os-name" is a transitive dependency of @octokit/rest

dottedmag22:02:52

This is for :browser

thheller22:02:20

ah I guess you didn't follow the instructions and didnt install shadow-cljs in the project

thheller22:02:39

npm install shadow-cljs in the project should fix it

dottedmag22:02:57

Thanks, it worked.

thheller22:02:28

os is one of those packages that needs a polyfill for the browser

dottedmag22:02:35

However I have a couple of questions: • where are the instructions? I don't see it in section (2) of the guide • what did it do to make it work?

thheller22:02:53

that polyfill is a dependency of shadow-cljs

dottedmag22:02:23

OK, that answers my second question 🙂

thheller22:02:57

I guess it could be clearer in the docs

dottedmag22:02:16

Indeed, the guide suggests to install shadow-cljs globally, and only reluctantly says "yes, you can install it local and use npx"

dottedmag22:02:53

Filed #648 so it does not get lost

thheller22:02:59

it was enforced for a while but people complained 😛

wiseman22:02:19

i’m having an issue with the :node-test target combined with watch that makes me wonder if i’ve missed something basic. i have

:test
  {:target :node-test
   :output-to "out/node-tests.js"
   :autorun true}
and i run npx shadow-cljs watch script test. but when i change a file, it seems like only a subset of my tests are automatically run. if i explcitly do node out/node-tests.js then they all run. what am i doing wrong?