Fork me on GitHub
#shadow-cljs
<
2019-02-19
>
r0man09:02:29

@thheller good morning. the problem I described yesterday happens in the browser

r0man09:02:51

if I print (prn (.-moduleInfoMap (loader/getModuleManager))) I get an empty map.

r0man09:02:09

but I think it should contain the module information

thheller09:02:27

that depends on where you print it. why are you printing it?

thheller09:02:05

shadow$loader should only be assigned once? do you see it reassigned again in the code somewhere?

r0man09:02:12

well, just before I load a module with (loader/load "my-module" callback)

r0man09:02:57

this call fails with the following exception:

thheller09:02:59

and what is the problem you are looking into again?

r0man09:02:02

I'm trying to get my modules working again under advances optimizations. it used to work, but doesn't anymore with shadow 2.8.2.

r0man09:02:20

when I look at my main module I see this in the beginning:

thheller09:02:06

hmm I never used that form. can you quickly try (-> (loader/load "my-module") (.then callback))?

thheller09:02:31

I suspect that the execOnLoad maybe was changed in the new closure lib (lots changed there)

r0man09:02:11

and in the middle of the main module there's other javascript that looks like this:

r0man09:02:41

which I think wipes out the module information.

r0man09:02:50

yes, I'll try the promise version

thheller09:02:52

hmm thats odd

r0man09:02:04

but I think it will have the same problem

thheller09:02:50

it may just be closure re-using the variable though

thheller09:02:56

it does weird optimizations like that

r0man09:02:24

the 2nd snippet I showed is the actual shadow.loader code, I think

r0man09:02:43

which uses the same namespace as the module info

thheller09:02:53

I really don't get why it is reassigned for you. I can't find any second assign in my code

r0man10:02:08

hmm, strange

r0man10:02:41

so at which point in your code is the shadow.loader namespace emitted

r0man10:02:15

are you using pseudo-names to look at the js?

thheller10:02:31

at the top as it should be

thheller10:02:42

both. tried with and without pseudo-names

r0man10:02:48

and the module info comes after that?

thheller10:02:05

var shadow$loader = {"uris":{"demo":["/js/demo.js"],"extra":["/js/extra.js"]},"infos":{"demo":[],"extra":["demo"]}};

r0man10:02:34

from the code I pasted above I don't understand how this can work. in the generated code I have, either the module info will wipe out the shadow.loader namespace or the other way around

thheller10:02:03

yes but I don't get where your second shadow$loader assignment is coming from

thheller10:02:07

that doesn't make sense to me

r0man10:02:28

if the shadow.loader code gets evaluated first, you might be lucky and the definitions are in the runtime by the time the module info wipes out the namespace

r0man10:02:57

I think it's the shadow.loader namespace

thheller10:02:05

;var $shadow$loader$ml$$ = new $goog$module$ModuleLoader$$;
$shadow$loader$ml$$.$sourceUrlInjection_$ = !0;
var $shadow$loader$mm$$;
!$module$contents$goog$loader$activeModuleManager_moduleManager$$ && $module$contents$goog$loader$activeModuleManager_getDefault$$ && ($module$contents$goog$loader$activeModuleManager_moduleManager$$ = $module$contents$goog$loader$activeModuleManager_getDefault$$());
$shadow$loader$mm$$ = $module$contents$goog$loader$activeModuleManager_moduleManager$$;
$shadow$loader$mm$$.$loader_$ = $shadow$loader$ml$$;

r0man10:02:29

@thheller What's directly in front of the ";"? first character on the first line?

r0man10:02:46

here is where I have the var shadow$loader = {}

thheller10:02:00

uhm some other code from another namespace

thheller10:02:15

but the problem is clear now

thheller10:02:22

at least in my setup

r0man10:02:37

goog.provide("shadow.loader");

thheller10:02:50

no the ns alias would be $shadow$loader

r0man10:02:13

but that's not what I'm seeing

r0man10:02:18

it's the same!

r0man10:02:25

at least in my file 🙂

thheller10:02:42

yes. but you are looking at the wrong thing

thheller10:02:55

I can reproduce this 100% if :module-loader is missing from the config

thheller10:02:14

try deleting all your output files and recompile again after restarting shadow-cljs

thheller10:02:32

just to ensure nothing is stuck somewhere and you are looking at the correct files

thheller10:02:31

var $goog$module$ModuleLoader$EventType$EVALUATE_CODE$$ = new $goog$events$EventId$$("evaluateCode$0"), $goog$module$ModuleLoader$EventType$REQUEST_SUCCESS$$ = new $goog$events$EventId$$("requestSuccess$1"), $goog$module$ModuleLoader$EventType$REQUEST_ERROR$$ = new $goog$events$EventId$$("requestError$2");
function $goog$module$ModuleLoader$EvaluateCodeEvent$$() {
  $goog$events$Event$$.call(this, $goog$module$ModuleLoader$EventType$EVALUATE_CODE$$);
}
$goog$inherits$$($goog$module$ModuleLoader$EvaluateCodeEvent$$, $goog$events$Event$$);
function $goog$module$ModuleLoader$RequestSuccessEvent$$() {
  $goog$events$Event$$.call(this, $goog$module$ModuleLoader$EventType$REQUEST_SUCCESS$$);
}
$goog$inherits$$($goog$module$ModuleLoader$RequestSuccessEvent$$, $goog$events$Event$$);
function $goog$module$ModuleLoader$RequestErrorEvent$$($moduleIds$jscomp$9$$, $opt_error$jscomp$4$$) {
  $goog$events$Event$$.call(this, $goog$module$ModuleLoader$EventType$REQUEST_ERROR$$);
  this.error = $opt_error$jscomp$4$$ || null;
}
$goog$inherits$$($goog$module$ModuleLoader$RequestErrorEvent$$, $goog$events$Event$$);
function $goog$module$ModuleLoader$LoadStatus$$() {
  this.$responseTexts$ = this.$requestUris$ = null;
  this.$loadRequested$ = !1;
  this.$errorFn$ = this.$successFn$ = null;
}
;var $shadow$loader$ml$$ = new $goog$module$ModuleLoader$$;
$shadow$loader$ml$$.$sourceUrlInjection_$ = !0;
var $shadow$loader$mm$$;
!$module$contents$goog$loader$activeModuleManager_moduleManager$$ && $module$contents$goog$loader$activeModuleManager_getDefault$$ && ($module$contents$goog$loader$activeModuleManager_moduleManager$$ = $module$contents$goog$loader$activeModuleManager_getDefault$$());
$shadow$loader$mm$$ = $module$contents$goog$loader$activeModuleManager_moduleManager$$;
$shadow$loader$mm$$.$loader_$ = $shadow$loader$ml$$;
$goog$global$$.shadow$loader && function() {
  $shadow$loader$mm$$.$setAllModuleInfo$($goog$global$$.shadow$loader.infos);
  var $uris$jscomp$6$$ = $goog$global$$.shadow$loader.uris;
  $shadow$loader$mm$$.$setModuleUris$ ? $shadow$loader$mm$$.$setModuleUris$($uris$jscomp$6$$) : ($goog$object$getKeys$$($uris$jscomp$6$$).forEach(function($key$jscomp$115$$) {
    var $trusted_uris$$ = [];
    $uris$jscomp$6$$[$key$jscomp$115$$].forEach(function($uris$jscomp$6$$) {
      var $key$jscomp$115$$ = new $goog$html$TrustedResourceUrl$$;
      $key$jscomp$115$$.$privateDoNotAccessOrElseTrustedResourceUrlWrappedValue_$ = $uris$jscomp$6$$;
      $trusted_uris$$.push($key$jscomp$115$$);
    });
    $uris$jscomp$6$$[$key$jscomp$115$$] = $trusted_uris$$;
  }), $shadow$loader$mm$$.$setModuleTrustedUris$($uris$jscomp$6$$));
}();

r0man10:02:31

I'm just experience the case that the shadow.loader namespace gets emitted AFTER the module info. in your case it seems to be the other way around

thheller10:02:11

what do you mean? do you not have var shadow$loader = ... assignment at the very top of the file?

thheller10:02:22

var shadow$provide = {};
if(typeof Math.imul == "undefined" || (Math.imul(0xffffffff,5) == 0)) {
    Math.imul = function (a, b) {
        var ah  = (a >>> 16) & 0xffff;
        var al = a & 0xffff;
        var bh  = (b >>> 16) & 0xffff;
        var bl = b & 0xffff;
        // the shift by 0 fixes the sign on the high part
        // the final |0 converts the unsigned value into a signed value
        return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0)|0);
    }
}

var shadow$loader = {"uris":{"demo":["/js/demo.js"],"extra":["/js/extra.js"]},"infos":{"demo":[],"extra":["demo"]}};

thheller10:02:40

that should be the absolutely only assignment ever

r0man10:02:21

yes, I have that. but in the same file the shadow.loader code is emitted after this module info declaration

thheller10:02:29

the code that translates the shadow$loader into the actual runtime data is coming way later

thheller10:02:31

that is normal yes

r0man10:02:37

which I think wipes the module info out

thheller10:02:43

please stop for a second

thheller10:02:52

lets clean up our understanding of the situation

thheller10:02:22

a) your COMPILED code contains two assigns for shadow$loader?

thheller10:02:29

does matter where

thheller10:02:02

ie if you grep your compiled code for shadow$loader = that should only find ONE occurence

thheller10:02:52

oh fuck .. I have a guess

thheller10:02:01

do you have :module-loader true in your build config?

r0man10:02:28

yes, I have :module-loader true.

r0man10:02:36

I think I tried without, but let me check again

thheller10:02:43

no it should be in there

thheller10:02:52

but again please answer my question

thheller10:02:58

how many assignments are there?

thheller10:02:20

the correct one at the top and the empty one later?

r0man10:02:54

but, let's clarify this also. shadow$loader is getting assigned 2 things. the module info and the shadow.loader namespace, right?

thheller10:02:11

ok I reproduced the problem now

r0man10:02:26

and the module info which is then used by the shadow.loader namespace

thheller10:02:40

if I remove :module-loader true from my config it breaks like yours

thheller10:02:57

I guess I messed up the automatic detection of that flag

thheller10:02:10

it is supposed to be detected automatically so you don't have to set it

thheller10:02:51

please check if you have :module-loader true in your config in the correct place

thheller10:02:00

:module-loader true :modules {...}

r0man10:02:02

just right above :modules, yes

r0man10:02:09

no, it's fine

thheller10:02:12

I can definitely reproduce it when it is not set but adding it fixes everything

thheller10:02:32

well. I'll fix it so you don't need to ever set it

metacritical12:02:00

Hi @thheller I am trying to add a ~/.b42 into the classpath in shadow-cljs.edn :source-paths but i think it doesnt resolve ~as home directory.

jlmr12:02:36

Hi, I’m getting [:did-not-find <name-of-ns>] errors for namespaces that do exist. What does this error indicate?

thheller12:02:02

@metacritical yes it doesn't resolve source paths at all. I wouldn't expect that to work in any java setup?

thheller12:02:56

@jlmr that happens in your (in-ns 'foo.bar) without having done (require 'foo.bar) first

jlmr12:02:14

Ok, thanks, will look at it further

jlmr12:02:27

For some reason the errors are not occuring now 🙂

idiomancy16:02:59

So, I'm getting this reference error when importing this js lib, and I see that is seems to be looking for an underscored version of the library. is that relevant to the problem? ReferenceError: module$node_modules$aws_appsync$lib$index is not defined

idiomancy16:02:56

seems to have sorted itself out, actually... I think it must have been outside the compile path for that build

wilkerlucio18:02:30

@thheller I noticed something a bit weird, I have in my project my own cljsjs files for some libs that we do override impl, I noticed if I put a .js file in the cljsjs ns and try to require it, shadow can't find it, but moving to a different folder cljsjs-mine for example makes it work, seems like its doing special threatment for cljsjs, is that expected?

thheller18:02:49

yes that is expected

thheller18:02:44

otherwise it would start inspecting all the files in cljsjs which would include all the foreign libs

thheller18:02:53

I'm probably removing the classpath indexing soon though since its not really all that useful

thheller18:02:02

then I could lift that restriction

wilkerlucio18:02:39

cool, thanks for the clarification