This looks like exactly the kind of operation that must occur at initialization time, as discussed in Modules · The Julia Language .
In particular, it mentions:
Depending on compile-time side-effects persisting through load-time. Example include: modifying arrays or other variables in other Julia modules…
Basically, you’re modifying that global during the precompilation process, but the resulting precompiled module doesn’t know that it’s supposed to modify that value every time PkgB is loaded.
You should get the expected behavior if you move that assignment into the __init__() function.