Fork me on GitHub
#shadow-cljs
<
2023-08-17
>
sb09:08:20

I tried to import this lib https://pdfmake.github.io/docs/0.1/getting-started/client-side/methods/ “pdfmake”, any idea how to import.. I got everytime errors, I don’t know how to import this lib in the right way (ns require) Yes, I know the docs url [https://shadow-cljs.github.io/docs/UsersGuide.html#npm] and I imported other npm libs without problem.. I saw that is closure compiler problem in the prev posts/ messages.

thheller09:08:32

how did you import and and what are the errors you get?

sb09:08:36

I found your prev. answer about this.. that is compiler problem.

thheller09:08:55

please answer the question anyways 😛

😁 2
sb09:08:52

failed to convert sources
{:tag :shadow.build.closure/convert-error, :sources [[:shadow.build.npm/resource "node_modules/pdfmake/build/pdfmake.js"]]}
ExceptionInfo: failed to convert sources
	shadow.build.closure/convert-sources-simple*/fn--57322 (closure.clj:1998)
	shadow.build.closure/convert-sources-simple* (closure.clj:1997)
	shadow.build.closure/convert-sources-simple (closure.clj:2169)
	shadow.build.closure/convert-sources-simple (closure.clj:2121)
	shadow.build.compiler/maybe-closure-convert (compiler.clj:1233)
	shadow.build.compiler/compile-all (compiler.clj:1461)
	shadow.build.api/compile-sources (api.clj:253)
	shadow.build/compile (build.clj:493)
	shadow.cljs.devtools.server.worker.impl/build-compile (impl.clj:360)
	shadow.cljs.devtools.server.worker.impl/do-resource-update (impl.clj:538)
	shadow.cljs.devtools.server.worker.impl/do-resource-update (impl.clj:495)
	shadow.cljs.devtools.server.util/server-thread/fn--60595/fn--60596/fn--60604 (util.clj:269)
	shadow.cljs.devtools.server.util/server-thread/fn--60595/fn--60596 (util.clj:268)
	shadow.cljs.devtools.server.util/server-thread/fn--60595 (util.clj:241)
	java.lang.Thread.run (Thread.java:833)
Caused by:
RuntimeException: INTERNAL COMPILER ERROR.
Please report this problem.

Invalid node in lhs: STRINGLIT / 13037:4  [length: 15] [source_file: node_modules/pdfmake/build/pdfmake.js] [original_name: __dirname]
  Node(GETELEM): node_modules/pdfmake/build/pdfmake.js:13044:0
exports["default"] = void 0;
  Parent(ASSIGN): node_modules/pdfmake/build/pdfmake.js:13044:0
exports["default"] = void 0;

sb09:08:05

same problem.. unfortunately 😉

thheller09:08:16

did you try requiring pdfmake/build/pdfmake.min.js instead?

🍻 2
sb09:08:41

hmm… ok, I try it! (one moment just I closed the project.. and restarting now…. )

sb10:08:02

Thanks I can load now! min.js works!

Jp Soares15:08:16

I'm using Antlr4 in my project, besides its module that I'm installing with NPM it generates js files that import the Antlr4 module. I'm having a reaaaaaally hard time trying to advance-compile it. By my research I saw that I have to define everything that shouldn't be renamed in my externs/app.txt, but as Antlr4 lib is huge I'd take ages to write it by checking errors and including in the .txt file. Am I missing something? Is there a way shadow-cljs recognizes the Antlr4 lib and avoid renaming everything that it's there? I've also downloaded the Antlr4 package to import it as a local lib, but it didn't change much.

thheller15:08:27

don't know enough about your setup to answer. npm deps do not go through :advanced, so require no externs

thheller15:08:42

so how do you import the generated js file? and what does a file like that look like?

thheller18:08:29

can you tell antlr to generate commonjs files? not esm? so no import/export? but require, module.exports?

Jp Soares18:08:18

Let me read the docs, but I don't think so.

thheller18:08:03

then your best open is to make it a pretend npm package

thheller18:08:24

so you create a packages/your-parser dir, npm init -y in that dir

👀 2
thheller18:08:40

put the files in that dir instead

thheller18:08:01

then in the build config :js-package-dirs ["packages" "node_modules"]

thheller18:08:13

then just (:require ["your-parser/whatever.js" :as x])

thheller18:08:11

that will process the files like any other npm package, so no :advanced probably no externs required

Jp Soares19:08:55

OMG it worked.. I spent so long on it :face_holding_back_tears: How can I thank you @U05224H0W? Maybe adding this tip to the UsersGuide?

thheller19:08:51

your previous method is actually the preferred one, I just haven't found a good way to "fix" it yet

thheller19:08:05

therefore in cases like yours you have to deal with externs too much

thheller19:08:00

but you are right, this method should be documented

hifumi12300:08:22

heh, I faced this exact same problem 5 months ago 😛

hifumi12300:08:15

However, I dont think the tip should be “wrap js files in NPM package”. It should be “js files imported in clojurescript go through advanced optimizations. if you would like to avoid this, then set up an npm package and require that instead”

thheller06:08:02

well, technically there is nothing stopping me from just disabling advanced for these files and treating them exactly like npm code

thheller06:08:07

and that may be the better choice from a developer experience side, I opted for :advanced because I maybe was too optimistic about it?

thheller06:08:28

another way to fix it I guess would be to do externs inference for JS files

hifumi12306:08:07

i wouldnt say optimistic… if you look at how antlr automatically generates JS code, it violates basically all of the rules on google’s website for writing javascript that can survive advanced compilation

😂 2
hifumi12306:08:14

e.g. mixing brackets and dot access for fields of an object

hifumi12306:08:31

this is anecdotal evidence, but i would say ~90% of JS files I import directly survive advanced compilation, the 10% is when I rely on auto-generated JS from tools like ANTLR 😛

seanstrom17:08:46

Is it possible to create a module-manifest with module-hash-names while targeting the esm format?

thheller17:08:28

no. those are all :browser only features.

thheller17:08:58

I also recommend outputting to a different directory, instead of module-hash-names

thheller17:08:26

so shadow-cljs release app --config-merge '{:output-dir "wherever/v1"}' and then use v2 and so on

thheller17:08:33

can you a git hash or whatever make sense for you

thheller17:08:05

manifest you don't really need since esm can just load the files it needs and doesn't need a loader

seanstrom17:08:41

okay sounds good. does that mean i don’t need to worry about manifest being used for anything else? And are you saying that the module-loader can be replaced by esm module loading?

thheller17:08:04

the module loader isn't compatible in the first place, so you cannot use it

seanstrom17:08:48

yup yup i understand, i guess i meant to ask if i’m moving from :browser to :esm targets that I can still module load stuff

thheller17:08:52

it also isn't necessary, since you can just use (shadow.esm/dynamic-import "./the-other-module.js")

seanstrom17:08:53

Ty ty 🙏 that’s exactly what I needed to know

greg20:08:32

I come across recently into that error:

[2023-08-17 17:07:31.633 - WARNING] :shadow.cljs.devtools.server.util/handle-ex - {:msg {:type :start-autobuild}}
AssertionError Assert failed: (map? rc)
        shadow.build.resolve/maybe-esm-rewrite (resolve.clj:208)   
        shadow.build.resolve/maybe-esm-rewrite (resolve.clj:208)                                                                                                                                                                             
        shadow.build.resolve/eval12490/fn--12492 (resolve.clj:422)                                                                                                                                                                           
        clojure.lang.MultiFn.invoke (MultiFn.java:244)                                                                 
        shadow.build.resolve/find-resource-for-string (resolve.clj:81)                                                                                                                                                                       
        shadow.build.resolve/find-resource-for-string (resolve.clj:70)                                                                                                                                                                       
        shadow.build.resolve/resolve-string-require (resolve.clj:460)                                                                                                                                                                        
        shadow.build.resolve/resolve-string-require (resolve.clj:443)                                                                                                                                                                        
        shadow.build.resolve/resolve-require (resolve.clj:675)                                                                                                                                                                               
        shadow.build.resolve/resolve-require (resolve.clj:668)                                                                                                                                                                               
        shadow.build.resolve/resolve-deps/fn--12393 (resolve.clj:52)                                                                                                                                                                         
        clojure.lang.PersistentVector.reduce (PersistentVector.java:343)                                                                                                                                                                     
Worker shutdown.
Latest shadow, latest cljs, build with :js-provider :external .

greg20:08:42

In the repo, here is shadow, webpack and babel to handle typescript. The error happen every time when generated classes are missing

greg20:08:51

So basically babel needs to be called before shadow

thheller20:08:54

hmm that doesn't seem like an error from :external? I mean that shouldn't even be calling that code?

greg20:08:40

I will share a demo repo, you can have a look if you want

thheller20:08:35

hmm ok that should be the error you get for file not found? so I'm guessing you have absolute require that doesn't exst

thheller21:08:40

I mean that should be a better error, but I think thats the cause there

greg21:08:38

Yes, this is file not found error I think, but it is not clear at the first glance 🙂

thheller21:08:43

you might be the first to use classpath js with :external, either are not very common. together you are probably the first 😉

2
😄 2
greg21:08:41

Here is the demo project: https://github.com/rynkowsg/demo-shadow-amplify The goal there is to: • use libraries like aws-amplify (that shadow can't resolve on its own) • use typescript in the same repo

thheller21:08:42

why can shadow not resolve on its own?

greg21:08:28

I'm not very much familiar with shadow internals, but it looks shadow looks for node dependencies and fails

greg21:08:39

This is the error if I let shadow to resolve the deps:

[:dev] Build failure:
The required JS dependency "http2" is not available, it was required by "node_modules/@aws-sdk/node-http-handler/dist/cjs/node-http2-handler.js".

Dependency Trace:
        demo/main/core.cljs
        node_modules/aws-amplify/lib/index.js
        node_modules/@aws-amplify/core/lib/index.js
        node_modules/@aws-amplify/core/lib/Providers/index.js
        node_modules/@aws-amplify/core/lib/Providers/AWSCloudWatchProvider.js
        node_modules/@aws-sdk/client-cloudwatch-logs/dist/cjs/index.js
        node_modules/@aws-sdk/client-cloudwatch-logs/dist/cjs/CloudWatchLogsClient.js
        node_modules/@aws-sdk/client-cloudwatch-logs/dist/cjs/runtimeConfig.js
        node_modules/@aws-sdk/node-http-handler/dist/cjs/index.js
        node_modules/@aws-sdk/node-http-handler/dist/cjs/node-http2-handler.js

Searched for npm packages in:
        /home/user/Sources/obrizum/shadow-amplify/node_modules
        /home/user/Sources/obrizum/shadow-amplify/src/js/components

thheller21:08:44

:face_vomiting: just looked at the aws-amplify package again. I remembered why I try to forget every time I see that 😛

2
thheller21:08:44

lets just require everything in the entire world, and rely on the build tool removing 99% of it ...

thheller21:08:19

no chance this will ever work with shadow-cljs, I'm not even gonna try

greg21:08:56

ok, I don't mind. I experienced similar mediocre quality with aws deps dedicated to run on android, so I guess they are consistent 🙂

greg21:08:39
replied to a thread:I come across recently into that error: [2023-08-17 17:07:31.633 - WARNING] :shadow.cljs.devtools.server.util/handle-ex - {:msg {:type :start-autobuild}} AssertionError Assert failed: (map? rc) shadow.build.resolve/maybe-esm-rewrite (resolve.clj:208) shadow.build.resolve/maybe-esm-rewrite (resolve.clj:208) shadow.build.resolve/eval12490/fn--12492 (resolve.clj:422) clojure.lang.MultiFn.invoke (MultiFn.java:244) shadow.build.resolve/find-resource-for-string (resolve.clj:81) shadow.build.resolve/find-resource-for-string (resolve.clj:70) shadow.build.resolve/resolve-string-require (resolve.clj:460) shadow.build.resolve/resolve-string-require (resolve.clj:443) shadow.build.resolve/resolve-require (resolve.clj:675) shadow.build.resolve/resolve-require (resolve.clj:668) shadow.build.resolve/resolve-deps/fn--12393 (resolve.clj:52) clojure.lang.PersistentVector.reduce (PersistentVector.java:343) Worker shutdown. Latest shadow, latest cljs, build with `:js-provider :external` .

This is the error if I let shadow to resolve the deps:

[:dev] Build failure:
The required JS dependency "http2" is not available, it was required by "node_modules/@aws-sdk/node-http-handler/dist/cjs/node-http2-handler.js".

Dependency Trace:
        demo/main/core.cljs
        node_modules/aws-amplify/lib/index.js
        node_modules/@aws-amplify/core/lib/index.js
        node_modules/@aws-amplify/core/lib/Providers/index.js
        node_modules/@aws-amplify/core/lib/Providers/AWSCloudWatchProvider.js
        node_modules/@aws-sdk/client-cloudwatch-logs/dist/cjs/index.js
        node_modules/@aws-sdk/client-cloudwatch-logs/dist/cjs/CloudWatchLogsClient.js
        node_modules/@aws-sdk/client-cloudwatch-logs/dist/cjs/runtimeConfig.js
        node_modules/@aws-sdk/node-http-handler/dist/cjs/index.js
        node_modules/@aws-sdk/node-http-handler/dist/cjs/node-http2-handler.js

Searched for npm packages in:
        /home/user/Sources/obrizum/shadow-amplify/node_modules
        /home/user/Sources/obrizum/shadow-amplify/src/js/components