Fork me on GitHub
#shadow-cljs
<
2019-07-19
>
currentoor04:07:11

can i have node_modules in a different directory than the top level?

currentoor04:07:36

i have a project that outputs builds for the browser and node

currentoor04:07:59

and some of the node deps aren’t installable on CI

currentoor05:07:41

ideally i’d have different profiles in package.json, but i don’t think that’s possible

jcb07:07:43

Has anyone come across this error before and how to resolve it? Running shadow-cljs... [:app] Compiling ... ------ WARNING #1 - ----------------------------------------------------------- Resource: com/cognitect/transit.js:649:8 variable module is undeclared -------------------------------------------------------------------------------- ------ WARNING #2 - ----------------------------------------------------------- Resource: com/cognitect/transit/impl/writer.js:256:8 variable isObject is undeclared -------------------------------------------------------------------------------- nil Thanks!

thheller07:07:27

@currentoor it is possible to set :js-options {:node-modules-dir "some/nested/path"} in your build config

thheller07:07:15

@jcb those are just warnings. not errors. not currently possible to resolve it since its a problem in the transit lib

jcb07:07:35

thanks @thheller, I'm trying to track down why a request to the server that works in dev would fail after uberjar

thheller07:07:56

it is not that. that causes no problems.

thheller07:07:00

what is the error you see?

jcb07:07:43

this is in luminus, so I'll take it there after I've been through some things. But essentially - In dev I'm sending a request for an edn file with some frontend config stuff in it. However, after compilation this fails. It not so much the error itself as the disparity between the dev experience (where everything just kind of works!) and the compiled code that is leading me down many rabbit holes.

thheller07:07:05

well how does it fail? what do you do with this edn config?

thheller07:07:16

remember that :advanced compiled builds are much less dynamic and certain dynamic things you can do in dev builds wont work

jcb08:07:25

I just swap it into a key in a state atom so that I can change some bits of the UI

thheller08:07:35

that sounds fine

thheller08:07:53

doing dynamic JS lookups or so wouldn't be

thheller08:07:10

but you still didn't mention what the actual error is

jcb08:07:50

sorry I've been trying to trace it back as I've been working through I've made many new errors. The initial problem was something along the lines of "replace" and "map" on null

jcb08:07:24

so I guess it's something to do with the way the request is returning

thheller08:07:47

so a null pointer usually indicates that something is null when it shouldn't be

jcb08:07:03

the structure itself was returning and readable in the chrome console

thheller08:07:06

that can happen if you for example access a JS property and the GCC decides to rename the name of that property

thheller08:07:33

ie. enable :compiler-options {:infer-externs :auto} in your build config and check the warnings (if there are any)

jcb08:07:08

I did that and there was a warning about some things from goog.history and goog.events but they seemed unrelated

thheller08:07:09

they might be but they might not be

thheller08:07:21

feel free to post them here. I can probably tell you

thheller08:07:34

you can also try shadow-cljs release your-build --debug to make things a bit easier to debug

jcb08:07:43

thank you! I will post them in a bit. I'm using luminus so should I add that into the uberjar tasks?

lmanolov08:07:42

Hi. Has somebody noticed a problem with too many generated JS files in dev mode? I guess I have too many NPM dependencies (like material-ui) but I don't see an easy way to reduce them. Currently, when I try to open the app in dev mode the browser does 1470 requests. I guess the real number is about 2900 including the .map files. The Chrome-based browsers (including Opera and Vivaldi) sometimes display error "net::ERR_INSUFFICIENT_RESOURCES" but most of the time just hang. Currently only Firefox can open the application but unfortunately, some tools like re-frisk don't work. Is there an option to combine the NPM resources in a single JS file in dev mode to reduce the number of requests?

jcb08:07:30

two infer warnings - (swap! session assoc :page (match-route (.-token event))))) -------------------------------------------------------^------------------------ Cannot infer target type in expression (. event -token)

jcb08:07:46

and (events/listen js/window EventType.KEYDOWN 648 | (fn [e] (reset! press (.-keyCode (.-event_ e)))))) -----------------------------------------------------------^-------------------- Cannot infer target type in expression (. e -event_)

thheller08:07:33

@jcb yeah that warning can be ignored. you can add (fn [^goog e] ...) to make that warning to away

thheller08:07:48

not sure what event_ is though. doesn't look like something you should be using directly

thheller08:07:03

so that may be the actual problem

thheller08:07:36

you can try (fn [^js e] ...) which will cause externs for event_ to be added. maybe that fixes it

jcb08:07:27

thank you I'll try it - it could be a problem but the request problem seem to be more about how formats are being en/decoded

thheller08:07:05

unlikely given that most apps use either EDN or transit or both and usually don't have any issues

thheller08:07:07

JSON is known to have some edge cases when using js->clj but EDN/transit don't have those issues

jcb08:07:14

ok, thanks for your time on this, I'll keep fumbling through 😅

lmanolov08:07:40

@thheller Thank you very much! The :loader-mode :eval option reduced the number of requests from 1470 to 30 and the Chrome-based browsers can open the application now

andrewzhurov11:07:34

Greetings, fellow clojurians! I seem to face an npm dependency issue, trying to add: https://github.com/funcool/cuerdasp into a deps.edn + shadow-cljs project I was unable to reproduce the same issue in a clean project, my dilettante guess would be that issue is caused by npm dependency clash package.json

"version": "0.0.1",
"private": true,
"devDependencies": {},
"dependencies": {
    "bootstrap": "^4.3.1",
    "core-js": "^3.1.4",
    "create-react-class": "^15.6.3",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-transition-group": "^4.2.1",
    "sass": "^1.18.0",
    "xregexp": "^4.2.4",
    "yarn": "^1.13.0"
    }
core-js is being required by xregexp and also create-react-class I don't have an idea of how it can be resolved (being new with using npm deps in cljs and shadow-cljs), any hints?

thheller11:07:35

@brownmoose3q check which version of core-js xregexp depends on via node_modules/xregexp/package.json. then make sure to install that version.

thheller11:07:44

might be 2.x not 3.x

andrewzhurov13:07:27

npm i --save [email protected]
did the trick! ta!

currentoor17:07:07

@thheller I noticed the user manual doesn’t mention :js-options {:node-modules-dir "some/nested/path"} anywhere, would you like a PR that adds a tiny note about it?

thheller17:07:07

sure why not

Lucas Senna17:07:18

Hi! I’m facing the following issue when running tests with shadow-clj configured with :ci {:target :karma}:

{
    "message": "Uncaught ReferenceError: $jscomp is not defined\nat ci.js:229378:1\n\nReferenceError: $jscomp is not defined\n    at ci.js:229378:1",
    "str": "Uncaught ReferenceError: $jscomp is not defined\nat ci.js:229378:1\n\nReferenceError: $jscomp is not defined\n    at ci.js:229378:1"
  }
The line that throws the error the is a transpilation of a js class extension:
$jscomp.inherits(ShuffleLoader$$module$nubank$shuffle$common$ui$shuffle_loader, module$node_modules$react$index.PureComponent);
Shadow-clj compiles and runs the app perfectly, the error only appears when running tests.

thheller17:07:56

hmm might be that the polyfills aren't inserted correctly for the karma build

thheller17:07:19

$jscomp is the var the GCC uses for polyfills

thheller17:07:57

you probably should set :compiler-options {:output-feature-set :es6} so it doesn't transpile classes

thheller17:07:23

don't really need to assuming you are running the tests in a somewhat recent platform

Lucas Senna17:07:10

Yep, our target is only a single evergreen browser. Changing the :compiler-options did the trick. Thank you very much!

👍 4
thheller17:07:31

FWIW if you use any newer features in the JS like async/await you can bump that up to :es7 or :es8

👍 4
currentoor19:07:40

has anyone seen this error?

{:clojure.main/message
 "Execution error at shadow.build/eval16057$loading (build.clj:1).\nUnable to resolve spec: :clojure.core.specs.alpha/args+body\n",
 :clojure.main/triage
 {:clojure.error/class java.lang.Exception,
  :clojure.error/line 1,
  :clojure.error/cause
  "Unable to resolve spec: :clojure.core.specs.alpha/args+body",

currentoor19:07:48

shadow-cljs - config: /Users/currentoor/src/ucv/shadow-cljs.edn cli version: 2.4.5 node: v10.16.0

currentoor19:07:00

ah it’s because my node_modules are in a subdirectory now…

thheller19:07:12

that doesn't look related to node_modules?

currentoor19:07:09

right i’m launching the server with npx shadow-cljs server

currentoor19:07:41

i agree it doesn’t look node_modules related, but calling npx ... in the same directory as my node_modules (now i have two in two separate dirs) launches the server

thheller19:07:09

you should launch it in the directory with your shadow-cljs.edn

thheller19:07:16

it'll do that anyways

currentoor19:07:35

but my shadow-cljs.edn and deps.edn are top level, so maybe i need a top level node_modules that just has shadow-cljs in it?

thheller19:07:34

well not really but that controls which version you get

thheller19:07:44

(of the npm package)

currentoor19:07:33

good grief, i find it baffling that JS with all it’s mindshare doesn’t have the notion of profiles in their dependency management

thheller19:07:55

I don't see how this has anything to do with JS

thheller19:07:02

its purely a clojure startup problem

thheller19:07:20

only guess I have is that you are using an older clojure version that doesn't have those specs?

thheller19:07:42

but that would be odd given that its a new style error message

thheller19:07:57

try deleting your .cpcache dir so deps.edn does its thing again

thheller19:07:03

maybe that got messed up somehow

currentoor19:07:14

this all would be a non-issue if in package.json i could just specify two profiles and do npm install --profile browser

currentoor19:07:34

in one context and npm install --profile node in another context

thheller19:07:58

not sure what you mean. this is a CLJ exception. CLJ never touches any JS whatsoever

thheller19:07:13

so whatever is happening is has nothing to do with npm/JS

currentoor19:07:16

i’m sorry i’m not being very articulate

currentoor19:07:45

you’ve already been immensely helpful, i should stop complaining 😅

thheller19:07:46

JS is a mess. I totally agree with that but can't blame it for everything 😉

currentoor19:07:30

but just in case you know, is there a way specify two different sets of dependencies in one package.json?

currentoor19:07:03

like how in deps i can say these deps are for only for a particular build

currentoor19:07:17

and the other deps are for all builds

thheller19:07:37

well people typically use dedicated directories with dedicated package.json files

currentoor19:07:41

right and i’m having trouble getting that approach to work with my shadow-cljs setup

thheller19:07:06

yes. I'm doing that in several places

currentoor19:07:20

ok so it is possible

thheller19:07:22

BUT it is absolutely impossible that :node-modules-dir prevents your process from starting

thheller19:07:41

that is why I want to get JS out of this discussion

thheller19:07:48

focus on what you are doing exactly

currentoor19:07:53

right i understand

thheller19:07:15

you have a shadow-cljs.edn presumably with a :deps and deps.edn

currentoor19:07:19

hmm i wonder if omitting npx might work

thheller19:07:34

so then please run shadow-cljs clj-repl in that directory

thheller19:07:49

with or without npx shouldn't really matter

currentoor19:07:45

nope i get the same error

thheller19:07:01

please paste the FULL error

currentoor19:07:12

i haven’t added :node-modules-dir just have package.json and node_modules in a subdirectory

currentoor19:07:01

sorry that was a little messed up

currentoor19:07:03

i’ll make a gist

currentoor19:07:26

do you need the rest of the stacktrace?

thheller19:07:48

what do you have set for :deps in shadow-cljs.edn?

currentoor19:07:18

:deps {:aliases [:test :cljs :dev]}

thheller19:07:43

so then run clj -A:test:cljs:dev please

currentoor19:07:20

that was able to spin a repl

thheller19:07:28

and then (require 'shadow.cljs.devtools.cljs-specs)

currentoor19:07:48

user=> (require 'shadow.cljs.devtools.cljs-specs)
nil

thheller19:07:23

do you have shadow-cljs in your deps.edn?

thheller19:07:29

if so which version?

currentoor19:07:06

under the alias :dev i have it thheller/shadow-cljs {:mvn/version "2.8.21"}

thheller19:07:48

so far everything looks good

thheller19:07:55

the rest of the stacktrace from above maybe?

thheller19:07:53

which clojure version is that?

currentoor19:07:11

1.10.1-beta2

currentoor19:07:43

i tried deleting both .cpcache and .shadow-cljs no luck

thheller19:07:26

run the previous clj command again please

thheller19:07:49

and check ( "clojure/core/specs/alpha.clj")

currentoor19:07:35

~/s/ucv (feature/barcode-scanner↑2|✔) $ clj -A:test:cljs:dev
Clojure 1.10.1-beta2
user=> ( "clojure/core/specs/alpha.clj")
#object[java.net.URL 0x5efb3259 "jar:file:/Users/currentoor/.m2/repository/org/clojure/core.specs.alpha/0.2.44/core.specs.alpha-0.2.44.jar!/clojure/core/specs/alpha.clj"]

thheller19:07:27

hmm yeah I get that same version

currentoor21:07:08

is there a reason why :js-options {:node-modules-dir "..."} would work for a :browser target but not :node-script

currentoor22:07:07

well i see you’re using it in shadow-cljs itself, so it should work

currentoor22:07:31

perhaps i need to :keep-native-requires

dfcarpenter23:07:35

I'm using shadow-cljs and VSCode/Calva and trying to reload a file with several functions I am making changes to. (require 'my.ns :reload-all) but this doesn't seem to work. Is this an effect of the caching? Do I need to turn this off completely when developing?

pez23:07:51

@dfcarpenter , there is something going on with loading files with Calva and shadow-cljs. I'm struggling to figure it out. Meanwhile, try selecting the whole file and then evaluate the selection.

👍 4