figwheel-main

figwheel-main http://figwheel.org
2020-05-31T00:04:15.090700Z

Is there some special way I should be setting :optimizations :advanced? All I have is this: my lein alias:

lein run -m figwheel.main -O advanced -bo min
min.cljs.edn:
^{:final-output-to     "resources/public/js/compiled/app.js"
  :open-url            false
  :watch-dirs          ["test" "src"]
  :css-dirs            ["resources/public/css"]}
{:main example.core
 :target :bundle
 :bundle-cmd {:default ["npx" "webpack" "--mode=production" :output-to "-o" :final-output-to]}
 :output-dir           "resources/public/js/compiled/"
 :source-map-timestamp true
 :devcards             true
 :closure-defines {cljs.core/*global* "window"
                   goog.DEBUG false}}

2020-05-31T00:57:26.090900Z

Right, flushed node_modules and reinstalled, and building min. Doesn’t work:

[Figwheel:SEVERE] Bundling command failed
Hash: b732264b26408a237e25
Version: webpack 4.43.0
Time: 39221ms
Built at: 05/31/2020 1:22:58 AM
 1 asset
Entrypoint main = app.js
[7] ./resources/public/js/compiled/main.js 1.14 MiB {0} [built]
[8] (webpack)/buildin/global.js 472 bytes {0} [built]
    + 16 hidden modules

ERROR in ./resources/public/js/compiled/main.js
Module not found: Error: Can't resolve 'react' in '/<project folder>/resources/public/js/compiled'
 @ ./resources/public/js/compiled/main.js 36:82-98 48:101-117 246:78-94
...
Just can’t resolve libs like react, react-dom again… Now devs not working either… Just trying to debug why…

bhauman 2020-05-31T01:10:46.091100Z

Yeah this is tough to do over text.

bhauman 2020-05-31T01:11:23.091300Z

You should make sure that you also delete the resources/public/js/compiled dir as well between runs

bhauman 2020-05-31T01:11:29.091500Z

just to be safe

bhauman 2020-05-31T01:12:00.091700Z

you should also try compiling in :simple

bhauman 2020-05-31T01:12:49.091900Z

and then bundling from the command line and try to follow the source of the errors, it seems like there is a bad require path or something

bhauman 2020-05-31T01:14:13.092200Z

also perhaps compile the advanced build to a completely different directory than the dev build

bhauman 2020-05-31T01:14:59.092400Z

also you may have a webpack.config.js that webpack is reading from?

2020-05-31T01:20:34.092700Z

Nope, not setting any webpack.config.js stuff, I didn’t want to mess around with any settings you might have created…

2020-05-31T01:21:42.092900Z

I’m normally flushing the compiled folder and the node_modules folder. I’ll try bundling from the command line…

2020-05-31T01:22:17.093100Z

btw this bit is correct right?

:bundle-cmd {:default ["npx" "webpack" "--mode=production" :output-to "-o" :final-output-to]}

2020-05-31T01:56:42.093300Z

Ok I’m doing this in stages as requested, not really had to debug webpack before, but something interesting, this is the first webpack error:

ERROR in ./resources/public/js/compiled/main.js
Module not found: Error: Can't resolve 'react' in '/<project-folder>/resources/public/js/compiled'
 @ ./resources/public/js/compiled/main.js 36:82-98 48:101-117 246:78-94
It’s caused by multiple places performing:
require("react")
which is as you suggested would be the problem, but the file itself has:
/** @license React v16.3.2
 * react.production.min.js
...
            ;(function(p,h){"object"===typeof exports&&"undefined"!==typeof module?module.exports=h():"function"===typeof define&&define.amd?define(h):p.React=h()})
I read that as it’s being exported as h? I thought that at this point the externs are not supposed to be minified?

bhauman 2020-05-31T13:37:59.093600Z

@folcon yeah so I assumed you had read this

bhauman 2020-05-31T13:38:00.093800Z

https://clojurescript.org/guides/webpack

bhauman 2020-05-31T13:38:18.094Z

especially https://clojurescript.org/guides/webpack#overriding-foreign-lib

2020-05-31T13:38:58.094200Z

Oh, sorry no. The first thing I saw was the npm guide that you’d written, if that’s necessary info, perhaps link that?

2020-05-31T13:39:07.094400Z

Reading =)…

2020-05-31T14:07:16.094600Z

With regards to overriding foreign libs, I’m not actually trying to use the npm react, I’m using another npm lib, but for some reason it’s not using the reagent react lib…

bhauman 2020-05-31T14:14:55.094900Z

oh ……!

bhauman 2020-05-31T14:15:04.095100Z

well thats the problem

bhauman 2020-05-31T14:15:19.095300Z

I think

bhauman 2020-05-31T14:15:43.095500Z

or a problem

bhauman 2020-05-31T14:17:14.095700Z

but it doesn’t seem like it should be a problem

bhauman 2020-05-31T14:17:53.095900Z

if there is a require(“react”) it’s not using the react cljsjs lib

bhauman 2020-05-31T14:18:50.096100Z

I don’t know why it would do that if react isn’t in node_modules

bhauman 2020-05-31T14:19:42.096400Z

but this is easy enough to fix for now

bhauman 2020-05-31T14:20:22.096600Z

npm install react react-dom and then exclude the ones in reagent

bhauman 2020-05-31T14:22:20.096800Z

but there may be a bug here or something we don’t understand so it might be worth maybe creating a small example of this behavior to verify it

bhauman 2020-05-31T14:22:25.097Z

I might try that

bhauman 2020-05-31T14:22:58.097200Z

but this is a clojurescript problem not a figwheel problem per-se

bhauman 2020-05-31T14:23:23.097400Z

but I definitely need to understand it because I want the NPM docs to cover this well

2020-05-31T14:26:35.097600Z

well that doesn’t answer what this is coming from?

Module not found: Error: Can't resolve 'xmlhttprequest' 

2020-05-31T14:30:02.097800Z

I mean this system does seem to assume that the user is basically swapping cljs libs for npm ones, but tracking that is not trivial =)…

bhauman 2020-05-31T15:48:37.098Z

I’m not sure that’s really true, I’m going to check that with reagent right now

bhauman 2020-05-31T15:50:18.098200Z

I’m not sure that should be happening

2020-05-31T16:07:28.098400Z

Perhaps not, I’m very willing to believe I’ve configured something incorrectly, but I have no idea what…

2020-05-31T17:43:14.098700Z

Found a clue on stackoverflow[0]:

The xmlhttprequest package is meant for server-side JavaScript.
Is there something specifying webpack is targeting server-side instead of the browser? - [0] https://stackoverflow.com/a/53421896

bhauman 2020-05-31T20:12:59.099Z

hmmm react-dom-server is intended to be server side

2020-05-31T20:28:37.099200Z

Yea, I can’t find anything in my code =)…