# Trouble creating Package Extension

**URL:** https://discourse.julialang.org/t/trouble-creating-package-extension/125767
**Category:** General Usage
**Tags:** package-extensions
**Created:** [February 10, 2025, 8:21pm UTC](https://discourse.julialang.org/t/trouble-creating-package-extension/125767 "2025-02-10T20:21:40Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Ken\_Williams](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ken_williams/32/5289_2.png) [@Ken\_Williams](https://discourse.julialang.org/u/Ken_Williams)
#### Post date: [February 10, 2025, 8:21pm UTC](https://discourse.julialang.org/t/trouble-creating-package-extension/125767/1 "2025-02-10T20:21:40Z")

</div>

I’m trying to create a package extension (see [5. Creating Packages · Pkg.jl](https://pkgdocs.julialang.org/v1/creating-packages/#Conditional-loading-of-code-in-packages-(Extensions))) for a package I’ve created, triggered by the `Plots` package.

I have the following in my package’s `Project.toml` file:

```julia
[extensions]
Plotting = "Plots"

```

and a file `ext/Plotting.jl` with the following:

```julia
module Plotting
using Plots
   ... functions
end # module

```

But then if I just try to launch a Julia session in this project, I get an error:

```julia
% julia --project=.
ERROR: LoadError: Trigger Plots for extension Plotting not found in project
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] Pkg.API.Precompilation.ExplicitEnv(envpath::String)
    @ Pkg.API.Precompilation ~/.julia/juliaup/julia-1.10.8+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Pkg/src/precompilation.jl:91
  [3] Pkg.API.Precompilation.ExplicitEnv()
    @ Pkg.API.Precompilation ~/.julia/juliaup/julia-1.10.8+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Pkg/src/precompilation.jl:33
  [4] _precompilepkgs(pkgs::Vector{String}, internal_call::Bool, strict::Bool, warn_loaded::Bool, timing::Bool, _from_loading::Bool, configs::Vector{Pair{Cmd, Base.CacheFlags}}, io::IOContext{IO}, fancyprint::Bool, manifest::Bool)
    @ Pkg.API.Precompilation ~/.julia/juliaup/julia-1.10.8+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Pkg/src/precompilation.jl:352
  [5] #precompilepkgs#5
    @ ~/.julia/juliaup/julia-1.10.8+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Pkg/src/precompilation.jl:333 [inlined]
  [6] (::Pkg.API.var"#225#226"{Bool, Bool, Bool, Bool, Bool, Vector{Pkg.Types.PackageSpec}})()
    @ Pkg.API ~/.julia/juliaup/julia-1.10.8+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Pkg/src/API.jl:1090
  [7] activate(f::Pkg.API.var"#225#226"{Bool, Bool, Bool, Bool, Bool, Vector{Pkg.Types.PackageSpec}}, new_project::String)
    @ Pkg.API ~/.julia/juliaup/julia-1.10.8+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Pkg/src/API.jl:1315
  [8] precompile(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; internal_call::Bool, strict::Bool, warn_loaded::Bool, already_instantiated::Bool, timing::Bool, _from_loading::Bool, kwargs::@Kwargs{io::Base.TTY})
    @ Pkg.API ~/.julia/juliaup/julia-1.10.8+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Pkg/src/API.jl:1088
  [9] precompile(pkgs::Vector{Pkg.Types.PackageSpec}; io::Base.TTY, kwargs::@Kwargs{_from_loading::Bool})
    @ Pkg.API ~/.julia/juliaup/julia-1.10.8+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Pkg/src/API.jl:159
 [10] precompile
    @ ~/.julia/juliaup/julia-1.10.8+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Pkg/src/API.jl:147 [inlined]
 [11] #precompile#114
    @ ~/.julia/juliaup/julia-1.10.8+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Pkg/src/API.jl:146 [inlined]
 [12] #invokelatest#2
    @ ./essentials.jl:894 [inlined]
 [13] invokelatest
    @ ./essentials.jl:889 [inlined]
 [14] _require(pkg::Base.PkgId, env::String)
    @ Base ./loading.jl:2033
 [15] __require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:1882
 [16] #invoke_in_world#3
    @ ./essentials.jl:926 [inlined]
 [17] invoke_in_world
    @ ./essentials.jl:923 [inlined]
 [18] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:1873
 [19] macro expansion
    @ ./loading.jl:1860 [inlined]
 [20] macro expansion
    @ ./lock.jl:267 [inlined]
 [21] __require(into::Module, mod::Symbol)
    @ Base ./loading.jl:1823
 [22] #invoke_in_world#3
    @ ./essentials.jl:926 [inlined]
 [23] invoke_in_world
    @ ./essentials.jl:923 [inlined]
 [24] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:1816
in expression starting at /Users/kwilliams/.julia/config/startup.jl:2
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.10.8 (2025-01-22)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

```

I’m confused by this - I don’t want to `add Plots` to this project, because it’s an _optional_ dependency, right? What’s the proper way to deal with this?

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [February 10, 2025, 8:31pm UTC](https://discourse.julialang.org/t/trouble-creating-package-extension/125767/2 "2025-02-10T20:31:26Z")

</div>

I think you need to `add` to `[weakdeps]`, Pkg REPL mode’s `add` needs the `-w`/`--weak` flag, or `Pkg.add` needs the `target=:weakdeps` keyword argument. That currently doesn’t change the `[extensions]` for you though, might be a problem with `weakdeps` not necessarily being a property of extensions: [Make `add --weak` automatically create extension entries · Issue #3549 · JuliaLang/Pkg.jl](https://github.com/JuliaLang/Pkg.jl/issues/3549)

---

<div class="post-metadata">

### Author: ![Ken\_Williams](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ken_williams/32/5289_2.png) [@Ken\_Williams](https://discourse.julialang.org/u/Ken_Williams)
#### Post date: [February 10, 2025, 8:36pm UTC](https://discourse.julialang.org/t/trouble-creating-package-extension/125767/3 "2025-02-10T20:36:00Z")

</div>

This option doesn’t seem to exist in the REPL for me:

```julia
pkg> add --weak Plots
ERROR: option 'weak' is not a valid option

```

Was this added in 1.11 maybe? I’m on 1.10 with this project.

---

<div class="post-metadata">

### Author: ![Ken\_Williams](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ken_williams/32/5289_2.png) [@Ken\_Williams](https://discourse.julialang.org/u/Ken_Williams)
#### Post date: [February 10, 2025, 8:39pm UTC](https://discourse.julialang.org/t/trouble-creating-package-extension/125767/4 "2025-02-10T20:39:20Z")

</div>

Just realized (as you said) that I can simply add

```julia
[weakdeps]
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"

```

manually to my `Project.toml` file, and this seems to work! Thanks. I haven’t tried out the actual extension yet, but this seems to get most things loading.

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [February 10, 2025, 8:41pm UTC](https://discourse.julialang.org/t/trouble-creating-package-extension/125767/5 "2025-02-10T20:41:23Z")

</div>

> [@Ken\_Williams](#):
>
> Was this added in 1.11 maybe?

Indeed, you’ll have to edit the file manually before that.
