# Understanding dependencies of packages extensions

**URL:** <https://discourse.julialang.org/t/understanding-dependencies-of-packages-extensions/115237>\
**Category:** General Usage\
**Tags:** package-extensions\
**Created:** [June 5, 2024, 3:20pm UTC](https://discourse.julialang.org/t/understanding-dependencies-of-packages-extensions/115237 "2024-06-05T15:20:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [June 5, 2024, 3:20pm UTC](https://discourse.julialang.org/t/understanding-dependencies-of-packages-extensions/115237/1 "2024-06-05T15:20:26Z")

</div>

I have a package and I’m extending a function to create plots. The main package depends on another third package, let’s say `StaticArrays` for simplicity, and the extension also uses the functions of `StaticArrays`. Should `StaticArrays` be also a `weakdep` for the extension?

Something like:

```julia
module MainPkg
    using StaticArrays
    export f
    function f end
end

```

extension:

```julia
module MyPkgExtension
    using Plots # the heavy weakdep
    using StaticArrays # should this be also a weakdep? Is it available?
    using MyPkg
    MyPkg.f(x::SVector) = plot(x)
end

```

I’m unsure if `StaticArrays` should be also a `weakdep`, and also if it is automatically “available” in the `MyPkgExtension` module for being a hard dependency of `MyPkg`.

From my tests it seems to be available, but I feel like doing something that can break easily.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [June 6, 2024, 11:41am UTC](https://discourse.julialang.org/t/understanding-dependencies-of-packages-extensions/115237/2 "2024-06-06T11:41:57Z")

</div>

I’m bumping this to understand better how extensions are implemented: are they to be seen as “nested modules” within the main package?

All the packages that are dependencies of the main package are already part of the environment of the extension?

It seems to be, but this is not explicitly written in the docs, so it feels now like trial-and-error.

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [June 6, 2024, 12:08pm UTC](https://discourse.julialang.org/t/understanding-dependencies-of-packages-extensions/115237/3 "2024-06-06T12:08:44Z")

</div>

> [@lmiq](#):
>
> I’m bumping this to understand better how extensions are implemented: are they to be seen as “nested modules” within the main package?
> 
> All the packages that are dependencies of the main package are already part of the environment of the extension?

I think one is only supposed to load the targets for the extension. Other dependencies are to be loaded transitively, e.g. as `using MainPkg.StaticArrays`, instead of `using StaticArrays`. This avoids cycles in package loading.

> <https://github.com/JuliaLang/julia/issues/48533>
>
> Originally posted by me in https://github.com/JuliaLang/julia/issues/48513#issue…comment-1416774301. Now making this an issue, since I think this really will need to be release blocking, as seems like possibly a significant reliability issue and heisenbug that is creeping upon the ecosystem.
> 
> \> Originally, I had that as the implementation and you went via Parent.Other to get dependencies. That however excluded the case where you wanted to load a package in an extension that was not a trigger nor was it loaded into Parent. This seemed to be a quite common desire so I allowed that. -Kristoffer
> 
> We observed recently that this should never have been allowed. It would be very useful, if it was valid. But it creates a cycle in the loading graph, which leads to unpredictable deadlocks, and causing the extension to sometimes hang (v1.9) or error (master today). It turns out that we must forbid this (for now), to prevent such unreliable behavior from catching users unawares and making PkgEval unreliable. We can re-evaluate later if we want to design a solution for it to reallow it later. Of note, it also must be forbidden (aka strongly discouraged) from loading those extra, unexpected packages via other mechanisms (e.g. during \`\_\_init\_\_\` or Requires.jl too) for the same reason that they will sometimes cause it to deadlock or error unpredictably.

> <https://github.com/JuliaStats/LogExpFunctions.jl/pull/63>
>
> Due to https://github.com/JuliaLang/julia/issues/48533, it might have to be nece…ssary to disable packages loading other dependencies other than their weak dependencies and the parent package. The rest of the packages have to be transitively loaded from the parent package. This does this fix for the packages loaded in the extensions.
> 
> cc @vtjnash

Although I’ve not kept up with the development, and this may not be necessary anymore.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [June 6, 2024, 12:17pm UTC](https://discourse.julialang.org/t/understanding-dependencies-of-packages-extensions/115237/4 "2024-06-06T12:17:00Z")

</div>

Uhm, in my package where I _do not_ do this “properly”, meaning, I don’t load the dependency by `MainPkg.StaticArrays`, I don’t get any warning or error message on Julia `nightly`, and the dev docs don’t mention that either. So it is unclear there if one should be careful with that, or no.

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [June 6, 2024, 1:20pm UTC](https://discourse.julialang.org/t/understanding-dependencies-of-packages-extensions/115237/5 "2024-06-06T13:20:02Z")

</div>

Yes, this is somewhat of a new development, and it’s not documented at all. I guess this is because the behaviour is still in flux

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [June 6, 2024, 2:11pm UTC](https://discourse.julialang.org/t/understanding-dependencies-of-packages-extensions/115237/6 "2024-06-06T14:11:53Z")

</div>

Nevertheless, when I changed my package to import the packages from the main package, I started getting these warnings:

```julia
[Info: Precompiling ComplexMixturesPlotting [72ee4039-6c6c-5d3e-ab5f-b48662531fd4]
┌ Warning: Module ComplexMixtures with build ID fafbfcfd-adc6-8079-0006-28dffa1c20f0 is missing from the cache.
│ This may mean ComplexMixtures [6f35c628-ac57-5bae-8ea9-703a8964f6e9] does not support precompilation but is imported by a module that does.
└ @ Base loading.jl:1948
[Info: Skipping precompilation since __precompile__ (false). Importing ComplexMixturesPlotting [72ee4039-6c6c-5d3e-ab5f-b48662531fd4].

```

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [January 8, 2025, 12:53pm UTC](https://discourse.julialang.org/t/understanding-dependencies-of-packages-extensions/115237/7 "2025-01-08T12:53:30Z")

</div>

Hi there, any news about this ? I’m trying to load an extension with multiple `weakdeps` but that fails for some reason. Have you tried that (given that you use _dependencies_ in your title) ?
