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}}
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…Yeah this is tough to do over text.
You should make sure that you also delete the resources/public/js/compiled dir as well between runs
just to be safe
you should also try compiling in :simple
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
also perhaps compile the advanced build to a completely different directory than the dev build
also you may have a webpack.config.js that webpack is reading from?
Nope, not setting any webpack.config.js
stuff, I didn’t want to mess around with any settings you might have created…
I’m normally flushing the compiled folder and the node_modules
folder. I’ll try bundling from the command line…
btw this bit is correct right?
:bundle-cmd {:default ["npx" "webpack" "--mode=production" :output-to "-o" :final-output-to]}
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?@folcon yeah so I assumed you had read this
especially https://clojurescript.org/guides/webpack#overriding-foreign-lib
Oh, sorry no. The first thing I saw was the npm guide that you’d written, if that’s necessary info, perhaps link that?
Reading =)…
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…
oh ……!
well thats the problem
I think
or a problem
but it doesn’t seem like it should be a problem
if there is a require(“react”) it’s not using the react cljsjs lib
I don’t know why it would do that if react
isn’t in node_modules
but this is easy enough to fix for now
npm install react react-dom and then exclude the ones in reagent
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
I might try that
but this is a clojurescript problem not a figwheel problem per-se
but I definitely need to understand it because I want the NPM docs to cover this well
well that doesn’t answer what this is coming from?
Module not found: Error: Can't resolve 'xmlhttprequest'
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 =)…
I’m not sure that’s really true, I’m going to check that with reagent right now
I’m not sure that should be happening
Perhaps not, I’m very willing to believe I’ve configured something incorrectly, but I have no idea what…
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/53421896hmmm react-dom-server is intended to be server side
Yea, I can’t find anything in my code =)…