Fork me on GitHub
#shadow-cljs
<
2021-11-01
>
awb9901:11:29

I am getting a compile error of a project that was working. And I have no idea what it coudl be:

awb9901:11:40

failed to resolve: ./iterator.js from /home/florian/repo/gorilla/goldly/profiles/bundelci/node_modules/vega-embed/build/vega-embed.js {:require-from #object[java.io.File 0x41bf4c6e "/home/florian/repo/gorilla/goldly/profiles/bundelci/node_modules/vega-embed/build/vega-embed.js"], :require "./iterator.js"} ExceptionInfo: failed to resolve: ./iterator.js from /home/florian/repo/gorilla/goldly/profiles/bundelci/node_modules/vega-embed/build/vega-embed.js shadow.build.npm/find-file (npm.clj:464)

awb9901:11:08

try { // add if support for Symbol.iterator is present require('./iterator.js')(Yallist$1); } catch (er) {}

awb9901:11:20

the js code is from the module vega embed.js

awb9901:11:45

I have no idea where iterator.js could come from. VEGA has 12 npm repos, and so many dependencies. typescript, etc.

awb9901:11:48

I have no idea where to start.

thheller07:11:24

@hoertlehner @alex.sheluchin that to me looks like a conditional require of some sort. shadow-cljs expects to find that file but doesn't. in fact nothing ever will find that so I don't know why that code is even in there. it appears to be new in the 6.20.0 release. 6.19.1 does not have it and likely compiles fine. or just create that file with just module.exports = function() {}; should be enough

Hukka07:11:29

Not the first time something "unexpected" happens inside the Vega builds. I'll file an issue there about this too, but I don't have high hopes of getting it fixed unless someone understands their build system well enough and digs into it

thheller07:11:29

yeah, their entire build system seems rather messed up. no clue why this is in the released builds, it can't serve any purpose

var scripts$1 = {
    prebuild: "yarn clean && yarn build:style",
    build: "rollup -c",
    "build:style": "./build-style.sh",
    clean: "del-cli build build-es5 src/style.ts",
    prepublishOnly: "yarn clean && yarn build",
    preversion: "yarn lint && yarn test",
    serve: "browser-sync start --directory -s -f build *.html",
    start: "yarn build && concurrently --kill-others -n Server,Rollup 'yarn serve' 'rollup -c -w'",
    pretest: "yarn build:style",
    test: "beemo jest --stdio stream",
    "test:inspect": "node --inspect-brk ./node_modules/.bin/jest --runInBand",
    prepare: "beemo create-config",
    prettierbase: "beemo prettier '*.{css,scss,html}'",
    eslintbase: "beemo eslint .",
    format: "yarn eslintbase --fix && yarn prettierbase --write",
    lint: "yarn eslintbase && yarn prettierbase --check",
    release: "auto shipit"
  };

thheller07:11:25

seems to import the entire package.json just to get the version out

Hukka07:11:58

That indeed seemed to be the gist of their latest release

Hukka07:11:40

I've gotten the feeling that perhaps build systems aren't their forte, but I don't know the background on how they then chose the tools they are using right now

Hukka07:11:31

A shame, really. The library has/had great potential, but I guess is severly lacking just contributors/maintainers in general, or at least those well versed in JS tooling

awb9911:11:25

Where do I have to crete this module.export ?

sheluchin12:11:30

@hoertlehner you could just use "vega-embed": "6.19.1", in your package.json if you don't really need anything in the newest release. @U05224H0W and @U8ZQ1J1RR thanks for looking into this. Not the greatest start with vega, but it was recommended as a good starting point for charting, so I'm going to stick with it a while and see if issues like this are frequent.

Hukka12:11:12

I rather see it as the end point, not the starting point. It's pretty heavy duty. But that's a discussion for another thread (and channel).

👍 1
awb9912:11:41

I fixed it by including this version. But I would like to know how I could fix it via the module.export.

awb9912:11:52

I am using vega-embbed not directly, but I use react-vega

awb9912:11:06

So I now have one additional dependency moure in my project.

awb9912:11:16

So I would rather fix it with some kind of hack.

awb9912:11:26

And who knows, it might be, that a new error appears in the future.

awb9912:11:29

vega breaks OFTEN

sheluchin12:11:57

@hoertlehner I think you can just include an iterator.js file with the contents module.exports = function() {};. https://shadow-cljs.github.io/docs/UsersGuide.html#_patching_libraries might be helpful.

awb9913:11:58

thanks a lot @alex.sheluchin

🙂 2
👍 1
thheller17:11:19

yeah you just put a iterator.js in the directory of the vega build file

thheller17:11:45

./iterator.js from /home/florian/repo/gorilla/goldly/profiles/bundelci/node_modules/vega-embed/build/vega-embed.js

thheller17:11:02

means it was trying to find /home/florian/repo/gorilla/goldly/profiles/bundelci/node_modules/vega-embed/build/iterator.js but couldn't since it does not exist

awb9920:11:02

but how can I add a directory to a npm temporary directory? I would need to first know when cljs watch has finihed getting the npm dependencies, so I could then manually add this file.

sheluchin20:11:01

I think if you just put the file in a mirrored location somewhere on your classpath, it should get picked up correctly when building.

thheller21:11:23

shadow-cljs watch doesn't get any npm dependencies ever

thheller21:11:41

at most it is installed when you start shadow-cljs

thheller21:11:06

but if you run npm install just before everything should already be ready and shadow-cljs won't install anything

thheller21:11:21

so you have the opportunity to modify whatever before shadow-cljs even runs

thheller21:11:34

but ... best option to me seems to not use a broken release?

sheluchin21:11:51

It's not an extra dependency anyway if it's already a subdependency of something you use.

awb9921:11:21

it would pick up a js file on the classpath?

sheluchin21:11:52

Ah, no, that's my mistake. You would need to put it next to the vega-embed.js file. But yeah, best option is to just roll back to a working release.

Hukka06:11:29

Coming back to this, would the module version of the vega-embed work better? That is, if you have :js-options {:entry-keys ["module" "browser" "main"]} in the build target.

Hukka06:11:15

https://unpkg.com/browse/[email protected]/build/vega-embed.module.js seems to be packaged completely differently and doesn't seem to try to import the missing file

Joshua Smock15:11:12

Hi 👋 I have two targets that compile some of the same code, one :browser and one :npm-module. For some reason automatic externs inferring isn’t working in :npm-module (and adding a line like :compiler-options :externs ["externs.js"] doesn’t help either) and so I get warnings for the :npm-module target that don’t show up in the :browser target. The warnings seem to be coming from using imported Node modules (so they necessarily must be JS functions) Is there something that needs to be done additionally to get externs inferring to work for :npm-module?

thheller17:11:37

@slack1338 for :browser shadow-cljs processes all JS and can infer a bunch of externs from that. for :npm-module that is not done since something else will provide the JS dependencies so you probably need a few more typehints

Joshua Smock17:11:12

I’m guessing it’s not possible or simple to assume any node module is JS and automatically infer that anything imported from it is ^js?

thheller17:11:41

I cannot see your code so I don't know what you are talking about specifically

thheller17:11:49

for npm imports this is already done yes

Joshua Smock17:11:19

I’ll try to come up with a minimal reproduction case and post here when I do. In any case from what I can tell it seems that the same code, compiled using these different targets, leads to different inferences and at least in this case code that should be inferred at JS isn’t in the :npm-module target. I assume it’s because, as you mention, the :browser target processes the JS code while the :npm-module target doesn’t

thheller17:11:51

just an example of the warning you get helps to infer what you are talking about

thheller18:11:06

I mean just adding the hints should solve it?

Joshua Smock09:11:33

Type hints would solve it but we don’t need them for our current app code (we don’t get warnings for the :browser compilation target) since the automatic externs inferring works in that case so it’s not a solution we would prefer to use if possible

thheller17:11:28

why not? they won't hurt the browser build and will in fact make it more reliable given that the compiler doesn't have to guess anymore.

Joshua Smock10:11:40

Well, primarily because we don’t need them for the browser build. In any case I will make a minimal repro repo and share with you here later

Joshua Smock19:11:02

@U05224H0W So we talked about adding type hints internally and are okay with it. I went ahead and tried to do it based on my understanding of how it should work and I think I uncovered a bug, but need more input - long story short in :target :npm-module target, if you use a JS function in a binding, and then later use that result in an anonymous function, it doesn’t seem to keep track of it even with a type hint and you’re forced to add a type hint in the anon function. https://github.com/jo-sm/shadow-externs-repro if you want to take a look, I tried to describe it as clearly as I can and am open to any ideas you have

thheller20:11:31

this is somewhat expected. you are welcome to make a enhancement patch for CLJS but as of now externs inference is not that smart

thheller20:11:41

but also kind of ambiguous. objects is a JS value as hinted (so probably an array) but you are map'ing over it and it does not automatically imply that each item in that array is also a JS value

thheller20:11:00

could be an array of CLJS maps, there is no way for the compiler to know this

Joshua Smock20:11:45

Sure, but the issue doesn’t appear with the :target :browser mode (even with externs inferring fully disabled), and it doesn’t get fixed with type hints as I understand them from the official reference. So I feel like something isn’t working as expected

Joshua Smock21:11:28

An alternative would be to just silence the warnings using :compiler-options {:warnings {:infer-warning false}} but I am also struggling to get that to work for :npm-module

Joshua Smock14:11:45

Anyway, if you have any ideas how to get around this let me know. The simplest approach would be to just shut the warnings up but it doesn’t seem to work (if I’m misplacing or misspelling the option, let me know), but adding type hints is also viable, but it also seems to work in an unexpected way (if my repro and understanding are correct)

thheller14:11:06

everything is working as intended. you found the correct place to add the typehint. just do exactly that.

thheller14:11:12

externs inference is never fully disabled

thheller14:11:19

you are only disabling the warnings

Joshua Smock14:11:30

sure, but disabling the warnings seems to do nothing

thheller14:11:38

and disabling the warnings will most likely lead to broken builds so just don't do it

Joshua Smock14:11:39

the warnings still appear in the terminal

Joshua Smock14:11:15

in this specific case disabling the warnings is acceptable as this is for tests, not for the main build of our application

thheller14:11:54

imho you should still run your tests using :advanced release builds. still might catch issues in your main build

Joshua Smock14:11:39

I’m a bit confused still - externs and :advanced aside, is it possible to disable warnings for :npm-module?

thheller14:11:51

you can try setting :js-options {:generate-externs false} in your :browser build config

thheller14:11:00

maybe that gets you do the same place as :npm-module

Joshua Smock14:11:42

I’m still missing the answer to my question 😅

thheller14:11:42

:compiler-options {:infer-externs false} should turn off warnings

thheller14:11:34

you can also set (set! *warn-on-infer* false) in a file after the ns or so to turn off all warnings in that file only

thheller14:11:28

but I repeat that the warnings are there for a reason and you probably spent more time talking to me about that problem than adding a few ^js would take

Joshua Smock14:11:43

ah ok so :infer-externs false does indeed fix it. Does it work differently than just disabling the warning (or does disabling the warning not work as I expect, which is that it won’t output it if it encounters it)?

thheller14:11:38

yes it'll still do the exact same inference. just not warn about it.

thheller14:11:59

disabling the warning likely just conflicts with the other setting defaulting to be enabled and overriding that setting

Joshua Smock14:11:47

Yeah it’s not that we are definitely going to disable the extern warnings - as you said they’re there for a reason - it’s more that we want to have the option to. In this specific case they’re being compiled for tests where we would expect the tests to fail for other reasons and this warning isn’t as relevant (unlike for the main build where it is more relevant). I was more trying to figure out why exactly the way that it seems like it should work according to the docs (adding :warnings {:infer-warning false} ) wasn’t

thheller17:11:44

and the warnings are not coming from import node modules. the warnings come from your cljs files

cjmurphy22:11:29

yarn shadow-cljs server is supposed to open a process that runs forever, until Cntl C out of it. But this morning, after an (attempted) OS upgrade, this is what I'm getting:

[chris@chris-latitudee7470 rad-b00ks]$ yarn shadow-cljs server
yarn run v1.22.15
$ /home/chris/rad-b00ks/node_modules/.bin/shadow-cljs server
shadow-cljs - config: /home/chris/rad-b00ks/shadow-cljs.edn
shadow-cljs - connected to server

Done in 0.13s. 
The process terminates! Same with yarn shadow-cljs watch. Actually yarn shadow-cljs server works fine for another project, with these two lines popping up after the config line:
shadow-cljs - HTTP server available at 
shadow-cljs - server version: 2.15.12 running at 
, and the process lasting forever as expected. There are no recently written log files to help diagnose, not in in the project root directory anyway.

cjmurphy22:11:23

Fixed by first deleting the .shadow-cljs directory that must have become corrupted. Doubt it had anything to do with the OS upgrade.

thheller06:11:11

shadow-cljs - connected to server is the hint. the server was already running

thheller06:11:33

by deleting .shadow-cljs you now likely have a zombie process thats no longer accessible. make sure to kill it manually.

cjmurphy07:11:21

ps -aux | grep shadow-cljs | less . Thanks.