# Clarification on extensions introduced in Julia v1.9 vs Requires.jl

**URL:** <https://discourse.julialang.org/t/clarification-on-extensions-introduced-in-julia-v1-9-vs-requires-jl/96371>\
**Category:** General Usage\
**Tags:** question, package\
**Created:** [March 21, 2023, 1:44am UTC](https://discourse.julialang.org/t/clarification-on-extensions-introduced-in-julia-v1-9-vs-requires-jl/96371 "2023-03-21T01:44:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Norman](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@Norman](https://discourse.julialang.org/u/Norman)\
**Post date:** [March 21, 2023, 1:44am UTC](https://discourse.julialang.org/t/clarification-on-extensions-introduced-in-julia-v1-9-vs-requires-jl/96371/1 "2023-03-21T01:44:43Z")

</div>

The introduction in the `Pkg` documentation makes me think that `extensions` is just like a built-in implementation of `@require`. But, after some initial attempt, I realized that they are not substitutes.

To be concrete, suppose I have a file that used to be handled by `@require` and is only loaded when package `A` is used. The file simply export an additional object when a package is loaded. To turn it into an extension, I wrap the content into a module and the file now looks like this:

```julia
module Attempt

export AdditionalObj

struct AdditionalObj end

end

```

Now I put `Attempt` into the `extensions` segment of `Project.toml`. I got

```julia
julia> Attempt
ERROR: UndefVarError: `Attempt` not defined

julia> AdditionalObj
ERROR: UndefVarError: `AdditionalObj` not defined

```

Are `extensions` not supposed to be used for defining new objects that need to be exported? So, they are only used to add additional methods for functions that are already existing in the parent package?

----------Updates----------

I would say what extensions do are making more sense to me now. It’s probably not good to export something new from extensions.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [March 21, 2023, 7:14am UTC](https://discourse.julialang.org/t/clarification-on-extensions-introduced-in-julia-v1-9-vs-requires-jl/96371/2 "2023-03-21T07:14:38Z")

</div>

@kristoffer.carlsson would be best qualified to answer, but I will try based on my interpretation of

- [Add support for "package extensions" to code loading by KristofferC · Pull Request #47695 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/47695/files) .
- [Code Loading · The Julia Language](https://docs.julialang.org/en/v1.9.0-rc1/manual/code-loading/#man-extensions) (dev version)
- [5. Creating Packages · Pkg.jl](https://pkgdocs.julialang.org/dev/creating-packages/#Conditional-loading-of-code-in-packages-(Extensions)) (dev version)

From what I can tell, the extension mechanism is primarily focused on extending methods, not necessarily introducing or exporting new types.

Based on [Are extension packages importable?](https://discourse.julialang.org/t/are-extension-packages-importable/92527/1) it might be possible to get a reference to the extension module itself.
