Fork me on GitHub
#shadow-cljs
<
2023-01-09
>
nivekuil08:01:32

shadow.loader/load is working in dev, but not in release. The error is CustomError: Error loading <module>: Consecutive load failures and the stacktrace is just as cryptic.. any troubleshooting ideas? The xhr to get the .js file does succeed but it's fetched 3 times and fails after the 3rd.

thheller09:01:19

is your server sending the correct response? usually the only happens when the server doesn't send the proper .js file?

thheller09:01:40

check the browser devtools which file it is requesting and what its contents are

thheller09:01:17

successful request unfortunately doesn't mean it contained the proper JS. could be sending some HTML instead

nivekuil09:01:36

yeah, looks like a bunch of JS, starting with SHADOW_ENV.evalLoad("shadow.modul...

thheller09:01:11

that is not a release file

nivekuil09:01:23

oops, you're right. one sec

nivekuil09:01:54

(function(){
shadow$provide[390]=function(ya,Ba,Ja,Ra){var qa=Ba(156);Ja.exports=function(){return qa.Date.now()}};
shadow$provide

nivekuil09:01:16

looks like it waits 5, then 20 secs between retries, then errors.. you'd think there would be some logging

thheller09:01:00

yeah the closure loader is not great when it comes to errors. usually there shouldn't be any though

thheller09:01:44

could be an error during load. try loading the files directly from the html if you can

thheller09:01:58

so just a html file that has the script tags for all the files in the correct order

nivekuil09:01:41

good call, making progress.

Uncaught TypeError: Cannot read properties of undefined (reading 'prototype')
looks like there's a mistake in my routing+loading system somewhere as the error points to this line
$APP.$reitit$core$t_reitit$0core609782$$.prototype.$reitit$core$Router$routes$arity$1$ = $JSCompiler_unstubMethod$$(5, function() {
  return this.$routes$;
});

thheller09:01:35

yuck not this again ...

thheller09:01:41

this is getting annoying 😉

thheller09:01:54

set :compiler-options {:cross-chunk-method-motion false} in your build config

nivekuil09:01:43

nice, you just saved me about three months of sleuthing

nivekuil09:01:49

so.. what is that?

thheller09:01:03

a very annoying issue related to reify in CLJS. https://clojure.atlassian.net/browse/CLJS-3207

👀 2
simon14:01:07

Hi all, newbie here.. I'm getting following error when compiling with target :node-library, and just wanted to ask here in case it's due to a simple oversight on my part.. it seems that async_hooks is a node-core-module, do I have to treat core-modules in a special way to make them available?

The required JS dependency "async_hooks" is not available, it was required by "node_modules/raw-body/index.js"

thheller14:01:49

uhm that error doesn't make sense. is this one of your files node_modules/raw-body/index.js? node-library doesn't process npm packages, so this weird

thheller14:01:30

or did you configure it specifically to bundle npm packages?

thheller14:01:49

and how did you require it? should be (:require ["async_hooks" :as x]), not (:require [async_hooks :as x]). ie a string not a symbol

simon15:01:50

thanks for the quick response! I love shadow-cljs, awesome user experience!! 🔥 node_modules/raw-body/index.js is not one of my files, probably pulled in in my import of express (:require ["express" :as express])

The required JS dependency "async_hooks" is not available, it was required by "node_modules/raw-body/index.js".

Dependency Trace:
	shadow/umd_helper.cljs
	test/lambdas/checkout.cljs
	node_modules/express/index.js
	node_modules/express/lib/express.js
	node_modules/body-parser/index.js
	node_modules/body-parser/lib/types/json.js
	node_modules/body-parser/lib/read.js
	node_modules/raw-body/index.js

Searched for npm packages in:
	/Users/user/dev/checkout/node_modules

simon15:01:11

could be a misunderstanding on my side how npm and node work, or shadow.. I think I've configured it based on your example of deploying a function to netlify

:stripe-checkout {:target :node-library
                    :output-to "landing/functions/checkout.js"
                    :exports {:handler test.lambdas.checkout/handler}
                    :js-options
                    {:js-provider :shadow
                     :keep-native-requires true}
                    :devtools
                    {:enabled false}}

thheller15:01:45

well yes, that configure it to make shadow-cljs bundle npm dependencies

thheller15:01:19

in that case you can add :keep-as-require #{"async_hooks"} to the :js-options map

thheller15:01:20

not you need to bundle everything in your case though

thheller15:01:27

its best if its not needed at all

simon15:01:33

woooow, thanks a lot, error is gone.. :star-struck:

simon15:01:49

what is best if it's not needed at all? the bundling?

thheller15:01:14

depends on the deployment. best to just let node load the dependencies, and just have shadow-cljs build the CLJS

thheller15:01:39

but that requires that the runtime can load npm packages. some can, some can't. not sure what you are deploying to

simon15:01:16

so you mean don't bundle any npm packages, because node will load them from node_modules? if I understood it right, that should work, because I'm deploying to netlify functions, and in the deployment it will install packages.json.

thheller15:01:53

yeah if the runtime can install npm packages its best to just remove :js-options from the config above

thheller15:01:27

but also fine to leave it when it works. 😉

simon15:01:53

hehehe, yeah, my usual approach.. I'll try it out though, makes sense

simon15:01:16

thanks a lot for your help! 😌 brings a bit more light into the shadow 😄

seanstrom16:01:50

Is it possible to create a release build for a npm-module target? I’m running into some issues when bundling the output with many errors like:

cljs-dist/cljs_env.js does not export 'Nf'
  > 1 | var window=global;var $CLJS=require("./cljs_env");require("./cljs_env.js");
  > 2 | 'use strict';$=require("react");module.exports=$;
  >   | 
And when I look at the cljs_env.js file, none of those fields exist. I’m using :advanced optimizations as well. Do I need to create some kind of externs file or something? It seems like the optimizations are removing those fields, but I’m not sure. Any ideas?

thheller17:01:10

what does cljs-dist/cljs_env.js does not export 'Nf' mean? its not supposed to be exported? what is generating this error?

thheller17:01:08

in fact what is generating this source at all? this doesn't look like npm-module output?

thheller17:01:24

require("./cljs_env");require("./cljs_env.js"); why is that duplicated?

seanstrom17:01:09

That’s generated by running the release command with shadow using this config:

{:source-paths ["src"]
 :dependencies [[reagent "1.1.1"]]
 :builds {:app {:output-dir "./cljs-dist"
                :target :npm-module
                :entries [app.main]
                :release {:compiler-options {:optimizations :advanced}}}}}

seanstrom17:01:29

When I use :simple optimizations that duplication does not happen.

seanstrom17:01:17

cljs-dist/cljs_env.js does not export 'Nf' refers to some mangled name that is supposed to be exported on the global $CLJS object / module

seanstrom17:01:16

But for some reason those fields are removed after the release build finishes. And when I try to use a tool like Webpack (in this case Parcel), the JS bundler reports that error

thheller18:01:51

and what do you do in your code?

thheller18:01:24

removing stuff is normal and expected. $=require("react"); $CLJS is the global object

thheller18:01:31

so that looks all exactly like its supposed to

thheller18:01:38

I'm missing what the actual problem is here?

thheller18:01:59

besides an error message I do not recognize and must be coming from other 3rd party tools

thheller18:01:03

might just be a linter trying to lint :advanced optimized output?

thheller18:01:30

so the question is: what is generating cljs-dist/cljs_env.js does not export 'Nf'? the error message I mean. the code is fine from what I can tell?

thheller18:01:57

hmm nvm. the code is broken. cljs-dist/cljs_env.js requiring cljs_env is indeed a bug, that should not be

thheller19:01:16

apologies. that error message really confused me. should be fixed as of 2.20.18, a bad cljs_env.js file was indeed being generated.

thheller19:01:32

not sure that error message if fixed now though 😛

seanstrom19:01:36

Haha no worries, I’m going to double check that the JS bundler is not doing something weird. If I keep running into the issue I’ll create a reproducible example to debug with you. Thank you for the help!