Fork me on GitHub
#figwheel-main
<
2020-05-09
>
mikerod00:05:28

@reefersleep you may benefit from learning about the :infer-externs option of the cljs compiler. You can turn this on via figwheel config too.

mikerod00:05:47

It’s pretty nice. Often you can just do a few type hints to get the externa you need.

reefersleep12:05:24

@mikerod cheers 🙂 I’m just in doubt about which files to use for which config things; figwheel had everything in the project.clj, figwheel-main has several config files and is very minimal in the template example.

mikerod12:05:53

Yes. That’s true. @reefersleep I do think it can be confusing at first. The fig docs are what I read through to know more options. It goes through them fairly extensively. Most things go in your dev.cljs.edn or <something>.cljs.edn depending on what you want to call it. Sometimes you have multiple

reefersleep12:05:01

We’ll get back to that. Thanks! 😄

reefersleep12:05:19

But for now, I tried moving away from two unknowns and into just 1, so I created a lein new reagent-frontend project, and am trying to just connect react-dnd correctly.

mikerod12:05:24

Hmm. Ok. Well if you find how to configure cljs compiler. I still recommend infer externs to do your Interop

reefersleep12:05:42

I’ll take that into consideration 🙂

reefersleep12:05:35

Currently stuck on a different issue; there’s a syntax error in the index.js-file I’m referring to. I don’t know why; it seems like ti’s referring to an undefined var.

reefersleep12:05:58

And it’s been long since I’ve concerned myself with vanilla js, and I’ve never done React in Js, so I can’t figure out if it’s because the compiler assumes a wrong version of js, or if it’s because the react-dnd lib has to go through some kind of compilation stage when used in regular React-in-JS - it seems like referring to a var that’s not defined in the same file is either generally foolish, or alright if you have very strong assumptions about the environment (like you might in React-in-JS)

reefersleep12:05:00

Some of the stackoverflow issues I’ve seen about a similar issue say it’s because the code assumes ES6, but specifying this for :language-in and :language-outmakes no difference at all.

reefersleep12:05:20

I do like this:

:cljsbuild {:builds {:app {:compiler {:language-in   :es6
                                      :language-out   :es6
                                      :foreign-libs  [{:file     "node_modules/react-dnd-cjs/lib/index.js"
                                                        :requires ["cljsjs.react"]}]
...
in the project.clj

reefersleep12:05:20

However, in the frontend console, I get

reefersleep12:05:34

(Uncaught referenceError: exports is not defined)

reefersleep12:05:49

Which I totally get, because the index.js file looks like this:

reefersleep12:05:53

"use strict";
function __export(m) {
    for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./common"));
__export(require("./hooks"));
__export(require("./decorators"));

reefersleep12:05:26

I don’t see the exports that is referred to as the first argument for `defineProperty) defined anywhere in the same file.

reefersleep12:05:00

Maybe React libraries are constructed in such a way that they assume things like an exports var to be available at all times, because it goes through some compilation stage when used in React-in-JS. idk. Or maybe ES6 just has it available as some global thing. If that’s the case, I just wonder why specifying that for :language-in and :language-out makes no difference.

mikerod12:05:31

I’ve never tried to use an node mode index.js like that.

mikerod12:05:08

Did this style setup for foreign-libs

reefersleep12:05:55

I might be going about this in entirely the wrong way. It’s just that there was only 1 way to install react-dnd according to their docs, and that was npm i react-dnd-cjs, which is what I did, while standing in my project dir.

reefersleep12:05:12

I’ll look at that link, thanks!

mikerod12:05:04

Well you get it from npm as usual

mikerod12:05:18

Then use webpack to build bundle to use from cljs via foreign-libs.

reefersleep13:05:10

That’s probably the step I was missing. Thanks a lot, I’ll read up on it and see if that helps 🙂

👍 4
reefersleep13:05:11

That means that any CI I would have liked to use would need to have node, npm and webpack installed as well, right? Currently I’m just fiddling about on my personal computer, but I’m trying to imagine a more realistic, professional setting at the same time.

mikerod14:05:17

You would need node installed yes. Typically this comes with npm I believe.

mikerod14:05:27

Webpack you can just pull via npm as a dev dependency.

👍 4
reefersleep14:05:42

I’m following the example in https://clojurescript.org/guides/webpack , having first created a minimal project as described in https://clojurescript.org/guides/quick-start . However, when I get to the part where I :require [react], and do clj -m cljs.main -co build.edn -v -c -r, I get an error in the browser:

reefersleep14:05:05

core.cljs:1 Uncaught ReferenceError: require is not defined
    at core.cljs:1

reefersleep14:05:55

That’s an error I don’t understand - it’s like cljs core has not loaded? Why would my application manage to compile, but not know :require?

reefersleep14:05:51

hello-world.core looks like this:

(ns hello-world.core
  (:require [react]))

(.log  js/console react/Component)

mikerod15:05:49

Nothing immediately comes to mind. I’d ask this same question on #clojurescript channel instead and probably would get good feedback

reefersleep15:05:38

Thanks, I’ll try that 🙂

reefersleep15:05:27

There seems to be no problem if I e.g. (:require [clojure.set :as set]) and use it afterwards, so I figure it does still have something to do with the bundled lib

mikerod15:05:47

So perhaps has to do with your foreign-libs declared

reefersleep15:05:36

I haven’t declared :foreign-libs anywhere. In this project, I’ve only done what it said in the tutorials.

reefersleep15:05:17

interestingly, there’s no mention of react in out/inferred-externs.js

reefersleep15:05:28

Hm 🙂 Seems it’s a case of the dark arts. I tried over with a completely new project, not reusing any code from one tutorial in the other, and now it works.

reefersleep15:05:01

That takes me some of the way… Maybe. Now I just have to get dark-arty as I try to figure out how to get this webpack-bundling setup to work together with figwheel-main.

reefersleep18:05:11

Alright, here we go again. I’m trying to use a minimal example project based on the tutorial in https://clojurescript.org/guides/webpack . That worked as intended. Then I tried expanding upon it to include figwheel-main using the tutorial at https://github.com/bhauman/figwheel-main#setting-up-a-build-with-tools-cli When running clj -m figwheel.main -b dev -r, I get the following error:

Rees-MacBook-Pro:hello-bundler ree$ clj -m figwheel.main -b dev -r
2020-05-09 20:30:02.933:INFO::main: Logging initialized @4507ms to org.eclipse.jetty.util.log.StdErrLog
[Figwheel] Compiling build dev to "target/public/cljs-out/dev-main.js"
internal/modules/cjs/loader.js:1023
  throw err;
  ^

Error: Cannot find module '@cljs-oss/module-deps'
Require stack:
- /Users/ree/dev/projects/hello-bundler/[eval]
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1020:15)
    at Function.Module._load (internal/modules/cjs/loader.js:890:27)
    at Module.require (internal/modules/cjs/loader.js:1080:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at [eval]:8:13
    at Script.runInThisContext (vm.js:131:20)
    at Object.runInThisContext (vm.js:297:38)
    at Object.<anonymous> ([eval]-wrapper:10:26)
    at Module._compile (internal/modules/cjs/loader.js:1176:30)
    at evalScript (internal/process/execution.js:94:25) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/Users/ree/dev/projects/hello-bundler/[eval]' ]
}
This error is mentioned in an old figwheel-main issue from 2018, but it says there that it’s fixed. Any idea what’s wrong?

reefersleep18:05:31

I’m thinking that maybe there’s a conflict in how the webpack tutorial sets up the target folder (`/out`) and where figwheel-main expects the target-folder to be (`target/public/cljs-out/{env}`). I tried resolving it by changing all references to out to the other folder, but nothing’s working so far, I still get the same error.

reefersleep18:05:33

I also tried npm install module-deps to ensure that it was in ./node_modules, no difference.

reefersleep18:05:08

Oh wait, I misread the install instructions for @cljs-oss/module-deps - it’s npm i @cljs-oss/module-deps!

reefersleep18:05:02

That gets me to a different a different state; it hangs forever at

Rees-MacBook-Pro:hello-bundler ree$ clj -m figwheel.main -b dev -r
2020-05-09 20:47:49.100:INFO::main: Logging initialized @5067ms to org.eclipse.jetty.util.log.StdErrLog
[Figwheel] Compiling build dev to "target/public/cljs-out/dev-main.js"