cljsrn

joshmiller 2022-05-24T20:44:41.728169Z

Has anyone here had any luck requiring .js or .jsx files from Krell? I cannot figure out what path the bundler wants me to give it.

joshmiller 2022-05-24T20:45:02.779619Z

The Juxt blog post here shows a directory structure: https://www.juxt.pro/blog/clojurescript-native-apps-2021

joshmiller 2022-05-24T20:46:19.869029Z

But reproducing what they’re describing doesn’t seem to work for me; no matter where I put the file or reference it, I see errors from the bundler (i.e., the output of yarn start) like:

ERROR  Could not evaluate  [TypeError: undefined is not an object (evaluating 'require("../src/file_for_later/ios/js/Test.jsx").default')]

joshmiller 2022-05-24T20:46:46.947139Z

I’ve essentially spammed every combo I can think of, with no luck.

joshmiller 2022-05-24T20:48:29.287249Z

I can start a blank project for a bare repro, but if someone here has been through this and can give me the secret before I try, happy to listen to ideas.

thheller 2022-05-24T21:16:03.841829Z

by "spammed every combo" do you mean doing this at the REPL?

thheller 2022-05-24T21:16:27.045059Z

JS dependencies need to be processed via metro which can't be done at the REPL. so JS deps in general are only available via a regular build

thheller 2022-05-24T21:17:07.572909Z

otherwise it should be a path relative to the output file of your CLJS. unless krell rewrites that in some way. not sure about that part.

joshmiller 2022-05-24T21:32:23.154629Z

Did it by changing and saving the file, then doing a reload from the simulator, which generated a new error with a different path from metro, so I’m pretty sure the changes are being picked up.

joshmiller 2022-05-24T21:34:18.188389Z

Relative to CLJS is what I tried first. The Juxt blog seems to imply it’s not that:

// src/app/components.cljs
(def utils (js/require "../src/stories/utils.js"))

joshmiller 2022-05-24T22:01:37.066889Z

I’ve confirmed in the output JS in target/ generated from my CLJS that the relative path refers to the place my JS file lives.

joshmiller 2022-05-24T22:02:30.017409Z

I’m wondering if I’m doing something wrong in writing the JS itself? I.e., the require(...) is returning undefined, so maybe it finds the file but doesn’t actually get anything out of it?

joshmiller 2022-05-24T22:45:15.304369Z

Having the same issue with assets (i.e., a png file), so I don’t think the issue is the JS.

hadils 2022-05-24T23:07:53.074279Z

Are you recompiling each time?

hadils 2022-05-24T23:09:07.726479Z

Also do you have your path in the deps.edn?

joshmiller 2022-05-24T23:20:08.917779Z

It does appear to be recompiling (i.e., the output JS in target/ changes)

joshmiller 2022-05-24T23:20:19.999239Z

I’m not sure what you mean about paths in deps.edn, so maybe I’m missing that?

hadils 2022-05-24T23:53:54.109189Z

In your deps.edn you need a :paths keyword. Here’s an example of mine:

:paths     ["src" "resources" "js" "components" "constants"]