# \`UndefVarError\` when using a custom, local package

**URL:** <https://discourse.julialang.org/t/undefvarerror-when-using-a-custom-local-package/62910>\
**Category:** New to Julia\
**Tags:** question, package\
**Created:** [June 14, 2021, 8:45pm UTC](https://discourse.julialang.org/t/undefvarerror-when-using-a-custom-local-package/62910 "2021-06-14T20:45:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erasmo98](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erasmo98/32/26098_2.png) [@Erasmo98](https://discourse.julialang.org/u/Erasmo98)\
**Post date:** [June 14, 2021, 8:45pm UTC](https://discourse.julialang.org/t/undefvarerror-when-using-a-custom-local-package/62910/1 "2021-06-14T20:45:29Z")

</div>

Hi, I’m new to Discourse. I want to start collaborating on packages so I’m descovering how it’s done. For so, I was trying to recreate [this example from the `Revise.jl` docs](https://timholy.github.io/Revise.jl/stable/cookbook/), which I can do perfectly with the `Example` package. First I do

```julia
pkg> dev Example
julia> using Revise
julia> using Example
julia> Example.hello("world")
"Hello world"

```

Then, whitout quitting the Julia session I modify the `Example.hello` function:

```julia
module Example

hello(who::String) = "Hello, revised $who"

end # module

```

Back in the Julia REPL I get the following

```julia
julia> Example.hello("world")
"Hello revised world"

```

so it’s working alright. The problem arises when I use a custom, local package. As in the previously mentioned, `Revised.jl` example, I begin creating a package:

```julia
julia> t = Template(user = "Erasmo98")
Template:
  authors: ["Erasmo98 and contributors"]
  dir: "C:\Users\Erasmo\.julia\dev"
  host: "github.com"
  julia: v"1.0.0"
  user: "Erasmo98"
  plugins:
    CompatHelper:
      file: "C:\Users\Erasmo\.julia\packages\PkgTemplates\60BEI\templates\github\workflows\CompatHelper.yml"
      destination: "CompatHelper.yml"
      cron: "0 0 * * *"
    Git:
      ignore: String[]
      name: nothing
      email: nothing
      branch: nothing
      ssh: false
      jl: true
      manifest: false
      gpgsign: false
    License:
      path: "C:\Users\Erasmo\.julia\packages\PkgTemplates\60BEI\templates\licenses\MIT"
      destination: "LICENSE"
    ProjectFile:
      version: v"0.1.0"
    Readme:
      file: "C:\Users\Erasmo\.julia\packages\PkgTemplates\60BEI\templates\README.md"
      destination: "README.md"
      inline_badges: false
      badge_order: DataType[Documenter{GitHubActions}, Documenter{GitLabCI}, Documenter{TravisCI}, GitHubActions, GitLabCI, TravisCI, AppVeyor, DroneCI, CirrusCI, Codecov, Coveralls, BlueStyleBadge, ColPracBadge]
      badge_off: DataType[]
    SrcDir:
      file: "C:\Users\Erasmo\.julia\packages\PkgTemplates\60BEI\templates\src\module.jl"
    TagBot:
      file: "C:\Users\Erasmo\.julia\packages\PkgTemplates\60BEI\templates\github\workflows\TagBot.yml"
      destination: "TagBot.yml"
      trigger: "JuliaTagBot"
      token: Secret("GITHUB_TOKEN")
      ssh: Secret("DOCUMENTER_KEY")
      ssh_password: nothing
      changelog: nothing
      changelog_ignore: nothing
      gpg: nothing
      gpg_password: nothing
      registry: nothing
      branches: nothing
      dispatch: nothing
      dispatch_delay: nothing
    Tests:
      file: "C:\Users\Erasmo\.julia\packages\PkgTemplates\60BEI\templates\test\runtests.jl"
      project: false

julia> t("MyExample")
[ Info: Running prehooks
[ Info: Running hooks
  Activating environment at `C:\Users\Erasmo\.julia\dev\MyExample\Project.toml`
    Updating registry at `C:\Users\Erasmo\.julia\registries\General`
    Updating git-repo `https://github.com/JuliaRegistries/General.git`
  No Changes to `C:\Users\Erasmo\.julia\dev\MyExample\Project.toml`
  No Changes to `C:\Users\Erasmo\.julia\dev\MyExample\Manifest.toml`
  Progress [========================================>] 1/1
1 dependency successfully precompiled in 1 seconds
  Activating environment at `C:\Users\Erasmo\.julia\environments\v1.6\Project.toml`
[ Info: Running posthooks
[ Info: New package is at C:\Users\Erasmo\.julia\dev\MyExample

julia> using MyExample
ERROR: ArgumentError: Package MyExample not found in current path:
- Run `import Pkg; Pkg.add("MyExample")` to install the MyExample package.

Stacktrace:
 [1] require(into::Module, mod::Symbol)
   @ Base .\loading.jl:871

```

I got this `ArgumentError` but I think I solved it doing

```julia
pkg> add "C:\\Users\\Erasmo\\.julia\\dev\\MyExample"
     Cloning git-repo `C:\Users\Erasmo\.julia\dev\MyExample`
    Updating git-repo `C:\Users\Erasmo\.julia\dev\MyExample`
   Resolving package versions...
    Updating `C:\Users\Erasmo\.julia\environments\v1.6\Project.toml`
  [02d13bce] + MyExample v0.1.0 `C:\Users\Erasmo\.julia\dev\MyExample#master`
    Updating `C:\Users\Erasmo\.julia\environments\v1.6\Manifest.toml`
  [02d13bce] + MyExample v0.1.0 `C:\Users\Erasmo\.julia\dev\MyExample#master`
Precompiling project...
  Progress [========================================>] 2/2
2 dependencies successfully precompiled in 3 seconds (155 already precompiled)

```

Now I can use `MyExample`

```julia
julia> using MyExample

```

and without quitting the Julia session, I create `MyExample.hello` function as follows.

```julia
module MyExample

hello() = "Hello world!"

end # module

```

I’m not getting the `ArgumentError` anymore but now I get this `UndefVarError`:

```julia
julia> MyExample.hello()
ERROR: UndefVarError: hello not defined
Stacktrace:
 [1] getproperty(x::Module, f::Symbol)
   @ Base .\Base.jl:26
 [2] top-level scope
   @ REPL[13]:1

```

Now I don´t know what to do. The problem is not with `Revise.jl` since I get the same error even after restarting Julia. I suspect that I’m not adding the package correctly. Shouldn’t Julia find my package by itself? Why do I need to add my package as follows?

```julia
pkg> add "path/to/package"

```

This is my first question so I don´t know if I’m asking it right.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [June 14, 2021, 9:43pm UTC](https://discourse.julialang.org/t/undefvarerror-when-using-a-custom-local-package/62910/2 "2021-06-14T21:43:21Z")

</div>

You should do `] dev path_to_example...` instead of `add` I think.

---

<div class="post-metadata">

**Author:** ![Erasmo98](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erasmo98/32/26098_2.png) [@Erasmo98](https://discourse.julialang.org/u/Erasmo98)\
**Post date:** [June 14, 2021, 10:05pm UTC](https://discourse.julialang.org/t/undefvarerror-when-using-a-custom-local-package/62910/3 "2021-06-14T22:05:32Z")

</div>

Thank you! The solution was easier than I thought. 😅
