Fork me on GitHub
#cljsrn
<
2022-05-24
>
joshmiller20:05:41

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.

joshmiller20:05:02

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

joshmiller20:05:19

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')]

joshmiller20:05:46

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

joshmiller20:05:29

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.

thheller21:05:03

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

thheller21:05:27

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

thheller21:05:07

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.

joshmiller21:05:23

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.

joshmiller21:05:18

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

joshmiller22:05:37

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.

joshmiller22:05:30

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?

joshmiller22:05:15

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

hadils23:05:53

Are you recompiling each time?

hadils23:05:07

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

joshmiller23:05:08

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

joshmiller23:05:19

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

hadils23:05:54

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

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