Fork me on GitHub
#shadow-cljs
<
2019-10-30
>
orestis09:10:57

@thheller Sorry to bother you again with this. Some more info with the broken stuff I'm seeing whenever I restart shadow-cljs. This seems to be the "root" error, AFAICT.

thheller09:10:07

no it is not the root

thheller09:10:25

it is just telling you that it failed to load that module. the reason that it failed is somewhere else

thheller09:10:34

above or below, can't remember right now

thheller09:10:51

just paste everything?

orestis09:10:03

try {
        moduleFn.call(
          module,
          goog.global,
          shadow.js.jsRequire,
          module,
          module["exports"]
        );
      } catch (e) {
        console.warn("shadow-cljs - failed to load", name);
        throw e;
      }

orestis09:10:25

It's a huge log that doesn't copy well -- but this snippet shows shows that the root error is below.

orestis10:10:14

The only "error" in the console is at the very end:

main.cljs:105 Uncaught TypeError: nosco.routes.start_routing_BANG_ is not a function
    at Object.nosco$views$main$start [as start] (main.cljs:105)
    at admin:14
nosco$views$main$start	@	main.cljs:105
(anonymous)	@	admin:14

thheller10:10:29

also not the root

thheller10:10:23

well it might be ... the problem is that it might not exist because loading it failed

thheller10:10:33

or it might not exist because of other reasons

thheller10:10:40

no way for me to tell without seeing more errors

orestis10:10:51

main.js:2176 failed to load nosco.views.page_list.js TypeError: global(...).default.createContext is not a function
    at Object.shadow$provide.module$node_modules$react_redux$lib$components$Context (Context.js:11)
    at shadow.js.jsRequire (js.js:63)
    at Object.shadow$provide.module$node_modules$react_redux$lib$components$Provider (Provider.js:15)
    at shadow.js.jsRequire (js.js:63)
    at Object.shadow$provide.module$node_modules$react_redux$lib$index (index.js:8)
    at shadow.js.jsRequire (js.js:63)
    at Object.shadow$provide.module$node_modules$react_beautiful_dnd$dist$react_beautiful_dnd_cjs (react-beautiful-dnd.cjs.js:14)
    at Object.shadow.js.jsRequire (js.js:63)
    at Object.shadow.js.require (js.js:97)
    at eval (/js/cljs-runtime/nosco.views.page_list.js:8)

thheller10:10:33

please ignore all "failed to load" errors

thheller10:10:09

well .. are there any others I mean?

orestis10:10:40

That's the whole console log

orestis10:10:07

Not sure if there's a better way to paste it...

thheller10:10:16

ok failed to load nosco.views.page_list.js TypeError: global(...).default.createContext is not a function that seems to be the actual error

thheller10:10:30

now .. to diagnose this further. please shutdown shadow-cljs completely

thheller10:10:41

DO NOT DELETE ANYTHING!

thheller10:10:46

just kill shadow-cljs

thheller10:10:15

then start the watch again and please verify that it does NOT say connected to server on startup

thheller10:10:20

that it is indeed restarting

orestis10:10:28

Done. BTW the offending file looks like so:

shadow$provide["module$node_modules$react_redux$lib$components$Context"] = function(global,require,module,exports) {
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports["default"] = exports.ReactReduxContext = void 0;

var _react = _interopRequireDefault(require("react"));

var ReactReduxContext = _react["default"].createContext(null);

exports.ReactReduxContext = ReactReduxContext;
var _default = ReactReduxContext;
exports["default"] = _default;
};

thheller10:10:40

looks exactly like it should

thheller10:10:57

well not exactly but close enough

orestis10:10:03

No other shadow running, verified by jcmd, here's the new startup log

shadow-cljs - config: /Users/orestis/dev/nosco/gamma/shadow-cljs.edn  cli version: 2.8.55  node: v12.9.0
shadow-cljs - starting via "clojure"
INFO  [main] org.xnio  - XNIO version 3.7.3.Final
INFO  [main] org.xnio.nio  - XNIO NIO Implementation Version 3.7.3.Final
INFO  [main] org.jboss.threads  - JBoss Threads version 2.3.2.Final
shadow-cljs - server version: 2.8.53 running at 
shadow-cljs - nREPL server started on port 61137

thheller10:10:35

ok and the compile finished with "Build completed"?

orestis10:10:07

[:main] Build completed. (852 files, 851 compiled, 0 warnings, 31,49s)

thheller10:10:30

what the heck? why did it compile so many files?

orestis10:10:55

And now everything works because I was poking around before, and renamed something in .shadow-cljs/builds/main/dev/. I have the original files around.

orestis10:10:32

I was hoping to do some debugging on my own before bothering you!

thheller10:10:46

you are not bothering me when reporting bugs/problems

❤️ 4
thheller10:10:57

I WANT to hear about them .. otherwise they never get fixed

thheller10:10:36

if people resort to the standard lein clean practice before compiling ... just because ... I'll consider this project failed.

thheller10:10:51

that is simply not acceptable to me 😛

thheller10:10:22

unfortunately the cache files alone don't help much in debugging

thheller10:10:45

but yeah the thing to look out for if you change depdendencies

orestis10:10:00

OK, just by killing the server and restarting shadow, I have the same problem.

orestis10:10:04

No new files, no new dependencies.

thheller10:10:06

is that you actually restarted and there is no second shadow-cljs instance running

thheller10:10:38

now it is in the broken state? what was the last "Build completed"?

orestis10:10:40

This time, [:main] Build completed. (851 files, 1 compiled, 0 warnings, 5,92s)

orestis10:10:03

Broken state, browser console.log is like the one I pasted

thheller10:10:12

now please make sure you have the browser cache completely cleared?

thheller10:10:22

I assume there is no Service Worker running?

orestis10:10:50

Yep, browser cache is disabled, serving files with Cache-Control: private, no-cache, no-store

orestis10:10:57

No service worker or fancy stuff

thheller10:10:55

ok. do you use multiple :modules or just one?

orestis10:10:02

Single module.

thheller10:10:16

so you have a rather large .js file that is loaded I presume?

orestis10:10:29

{:target :browser
         :output-dir "dev-resources/public/main/js"
         :asset-path "/js"
         :modules {:main {:entries [nosco.views.main]}}
         :compiler-options {:infer-externs :auto}
         :devtools {:watch-dir "dev-resources/public/main"
                    :loader-mode :eval}
         :release {:output-dir "gamma-dist/main/js"
                   :closure-defines {nosco.routes/WORMHOLE-EXIT true
                                     nosco.controllers/ALL-FEATURE-FLAGS-ENABLED false}
                   :module-hash-names true
                   :cache-blockers #{gamma.translate}
                   :build-hooks [(gamma.translate/write-pot-file "translations/gamma.pot")
                                 (gamma.translate/clear-messages)]
                   :build-options {:manifest-name "manifest.json"}}}

orestis10:10:45

That's the build conf, single large .js file, deps.edn for dependencies.

thheller10:10:11

ok then check the dev-resources/public/main/js/main.js file

orestis10:10:05

11MB. I can share if it helps?

thheller10:10:33

that'd be good yes

thheller10:10:57

ok one thing that I would suggest

thheller10:10:26

it looks like you have a top level function call directly in your nosco.views.main?

orestis10:10:09

No, that's called by index.html:

<script src="/js/main.js"></script>
    <script>
      nosco.views.main.start(document.getElementById("main"))
    </script>

orestis10:10:15

The code for that is

(defn ^:export start [el]
  (reset! EL el)
  (add-watch nosco.controllers/app-state :main-render
             (fn [_ _ _ s]
               (js/console.log "new state is " s)
               (let [{:keys [user siteConfiguration]} s]
                 (when (and user siteConfiguration)
                   (js/console.log "initial render")
                   (react-dom/render
                    (hx/f [Main])
                    el)))))
  (routes/start-routing!))

thheller10:10:58

can you take out the start call for a second?

thheller10:10:09

just to remove some errors

thheller10:10:15

what does nosco.views.page_list do?

thheller10:10:25

seems like it does some code on load?

orestis10:10:03

(ns nosco.views.page-list
  (:require
   [hx.react :as hx :refer [defnc]]
   [hx.hooks :refer [useState useContext]]
   [nosco.ui.table :as table]
   [nosco.ui.components :as components]
   [cljs-bean.core :refer [bean ->clj ->js]]

   ["react-beautiful-dnd" :refer [DragDropContext Droppable Draggable]]))


(def initial-items
  (mapv #(hash-map :order % :id (str "oid-" %) :title (str "Item " %)) (range 10)))

orestis10:10:21

Apart from a defining a bunch of components, that's the only "work" it does.

thheller10:10:54

@orestis I found something suspicious

thheller10:10:18

SHADOW_ENV.evalLoad("module$node_modules$React$index.js"

thheller10:10:40

SHADOW_ENV.evalLoad("module$node_modules$react$index.js"

thheller10:10:50

I guess that can be considered a bug

thheller10:10:57

you are including 2 versions of react on the page

thheller10:10:22

do you have a (:require ["React" ...] somewhere in your code or is that caused by some library?

orestis10:10:07

I’ll check! Thanks for the detective work.

thheller11:10:15

nosco.controllers seems to be it

orestis11:10:20

Yup, that's it.

orestis11:10:40

["React" :as React] -- in all other files, there is ["react" :as React]

thheller11:10:17

I have no clue why that would break stuff but it is one suspicious thing I found

orestis11:10:47

I'm on macOS which I is case insensitive, so the filename resolves to the correct file I guess.

orestis11:10:38

How should I debug this now? Changing the import and relying on hot reload threw an error.

thheller11:10:05

well that'll require a full page reload

thheller11:10:15

it is in a state that can't be hot-reloaded otherwise

thheller11:10:35

not sure this is the cause of your issues ...

thheller11:10:42

just looked weird when looking through the code

orestis11:10:44

Still the same error. Would force compile help?

thheller11:10:05

what error?

orestis11:10:31

There might be a chance that with all other react libraries, something else might be doing the same thing, but I think that various CI tools would catch it.

orestis11:10:08

Same errors in browser console.

orestis11:10:19

Should I restart something?

thheller11:10:00

hmm maybe try wiping the cache

thheller11:10:11

I think this might be the cause of all sorts of weird issues

orestis11:10:32

So that would be .shadow-cljs/builds/main? Is that the "root" cache?

thheller11:10:11

I think this might be the actual cause of your problems .. let me know if it happens again

orestis11:10:23

And should it be done while shadow is running? Or should I stop shadow, wipe the cache, start again?

thheller11:10:49

stopping the build would be enough

thheller11:10:05

ok I think I found the bug causing this ... something I've been meaning to address for a while

thheller11:10:30

but yeah it should be fixed in you stick to "react" only

orestis11:10:58

Things are working again (but they always work if I blow away the cache). I'll start over again and see what happens.

orestis11:10:37

Works! Many thanks for helping here. Final question, is calling the start function from HTML discouraged?

thheller11:10:39

no that is fine. from the stacktraces it just looked like things were going wrong while loading because of the start call

thheller11:10:05

but they weren't ...

orestis11:10:50

Cool. I've just noticed your Github sponsor page is online, so... 😄

thheller11:10:23

thanks 🙂

thheller11:10:11

still trying to figure out how your bug actually happens ... seems like it should either always happen or never

thheller11:10:19

not quite sure why it breaks after a restart

thheller11:10:17

but I added an additional check that should make the error easier to find 😛

orestis11:10:27

Happy to help if I can.

orestis14:10:21

@thheller I think case-(in)sensitivity is a major theme in my codebase 😄. Just found a case where importing date-fns/parseIso (wrong) vs date-fns/parseISO (correct) was breaking. The funny thing is that: (:require ["date-fns/parseIso" :as parseIso]) was returning something (an empty js object), which then broke downstreams consumers.

thheller15:10:27

@orestis that problem should be fixed in master

khellang15:10:33

Does anyone have a quick example on how to generate a basic index.html using manifest.edn?

thheller15:10:01

I added something basic recently that does that

thheller15:10:14

well it doesn't generate html, but it can update html 😛

thheller15:10:42

basically you create and basic html file you want

thheller15:10:13

and in your build config

:build-hooks
   [(shadow.html/copy-file
      "out/demo-browser/index.src.html"
      "out/demo-browser/public/index.html")]

thheller15:10:53

basically that'll replace the <script src="/js/base.js" defer></script> with <script src="/js/base.<hash>.js" defer></script>

thheller15:10:12

generating the HTML is also very easy if you use something like hiccup

khellang15:10:46

can I use shadow.html directly in shadow-cljs.edn?

khellang15:10:50

> Could not locate shadow/html__init.class, shadow/html.clj or shadow/html.cljc on classpath.

thheller15:10:49

it is rather new so you probably need to bump versions

khellang15:10:43

bumped version, this time it ran, but I don't see the file

khellang15:10:10

I see the build should've logged something if the source path was wrong

thheller15:10:32

maybe the warning is only visible if you run with --verbose

khellang16:10:29

ah, {:type :shadow.html/source-does-not-exist, :source "public/js/index.src.html", :shadow.build.log/level :info}

thheller16:10:22

it should probably just throw instead 😛

khellang16:10:35

but the file is there :thinking_face:

khellang16:10:53

:man-facepalming:

thheller16:10:55

this needs to be an actual file, not a classpath resource 😛

khellang16:10:01

it's not in the js folder 😂

khellang16:10:09

I think it's time to go home... thanks so much for shadow-cljs and your help 🙂

👍 4
khellang16:10:29

it worked now

Pavel Klavík18:10:45

Hi, I am trying to call a constructor for JS object from npm as follows:

(:require ["bezier-js" :as bezier])
(bezier/Bezier. x1 y1 x2 y2 x3 y3)
The object is from this library: https://pomax.github.io/bezierjs/#constructor. I am getting this error:
TypeError: module$node_modules$bezier_js$index.Bezier is not a constructor
    at orgpad$client$util$geom_link$create_quadratic_bezier_from_control_point (orgpad/client/util/geom_link.cljs:39:9)
    at eval (eval at shadow$cljs$devtools$client$browser$global_eval (/js/compiled/cljs-runtime/shadow.cljs.devtools.client.browser.js), <anonymous>:1:73)
    at eval (<anonymous>)
    at Object.shadow$cljs$devtools$client$browser$global_eval [as global_eval] (/js/compiled/cljs-runtime/shadow.cljs.devtools.client.browser.js:829:16)
    at eval (/js/compiled/cljs-runtime/shadow.cljs.devtools.client.browser.js:838:44)
    at Object.shadow$cljs$devtools$client$env$repl_call [as repl_call] (/js/compiled/cljs-runtime/shadow.cljs.devtools.client.env.js:145:108)
    at Object.shadow$cljs$devtools$client$browser$repl_invoke [as repl_invoke] (/js/compiled/cljs-runtime/shadow.cljs.devtools.client.browser.js:836:46)
    at shadow$cljs$devtools$client$browser$handle_message (/js/compiled/cljs-runtime/shadow.cljs.devtools.client.browser.js:921:37)
    at eval (/js/compiled/cljs-runtime/shadow.cljs.devtools.client.env.js:294:151)
    at Object.shadow$cljs$devtools$client$env$process_next_BANG_ [as process_next_BANG_] (/js/compiled/cljs-runtime/shadow.cljs.devtools.client.env.js:273:90)

Pavel Klavík18:10:48

I can access functions from that module, i.e.,

(.quadraticFromPoints bezier ...)

lilactown18:10:54

@pavel.klavik unfortunately, how to import foreign JS can often vary depending on how the JS is packaged

sogaiu18:10:14

is there a way to use new in this situation?

lilactown18:10:26

you should (js/console.log bezier) to see what the exported object is

lilactown18:10:19

based on their docs, I would expect that you would use the bezier as the constructor but it’s hard to know for sure

thheller18:10:32

@pavel.klavik pretty good chance it should be (bezier. x1 y1 x2 y2 x3 y3)

☝️ 4
Pavel Klavík18:10:07

cool, it works

thheller18:10:19

var Bezier = require('bezier-js')

thheller18:10:38

translates to the above

kenny21:10:34

I'm trying to use https://github.com/Pikaday/Pikaday. shadow-cljs fails the build with

The required JS dependency "moment" is not available, it was required by "node_modules/pikaday/pikaday.js".
However, the GitHub library page says "No dependencies (but plays well with Moment.js)". Why does shadow think it needs it?

kenny21:10:16

Is there a way to tell shadow that I actually don't need a dependency? The error message seems to hint that shadow isn't sure: "You probably need to run:"

You probably need to run:
  npm install moment

thheller21:10:54

try :js-options {:resolve {"moment" false}} in your build config

thheller21:10:19

there is no "standard" for optional dependencies

thheller21:10:23

so shadow-cljs can't tell

kenny21:10:34

That does fix it btw.

thheller21:10:23

this pattern is rather uncommon

kenny21:10:03

Sure. Still seems useful. Pretty widely known lib - 6.8k stars.

thheller21:10:24

the library seems rather old given that it uses browserify as an example