`UndefVarError` when using a custom, local package

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, which I can do perfectly with the Example package. First I do

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:

module Example

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

end # module

Back in the Julia REPL I get the following

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> t = Template(user = "Erasmo98")
  authors: ["Erasmo98 and contributors"]
  dir: "C:\Users\Erasmo\.julia\dev"
  host: "github.com"
  julia: v"1.0.0"
  user: "Erasmo98"
      file: "C:\Users\Erasmo\.julia\packages\PkgTemplates\60BEI\templates\github\workflows\CompatHelper.yml"
      destination: "CompatHelper.yml"
      cron: "0 0 * * *"
      ignore: String[]
      name: nothing
      email: nothing
      branch: nothing
      ssh: false
      jl: true
      manifest: false
      gpgsign: false
      path: "C:\Users\Erasmo\.julia\packages\PkgTemplates\60BEI\templates\licenses\MIT"
      destination: "LICENSE"
      version: v"0.1.0"
      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[]
      file: "C:\Users\Erasmo\.julia\packages\PkgTemplates\60BEI\templates\src\module.jl"
      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
      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.

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

I got this ArgumentError but I think I solved it doing

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> using MyExample

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

module MyExample

hello() = "Hello world!"

end # module

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

julia> MyExample.hello()
ERROR: UndefVarError: hello not defined
 [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?

pkg> add "path/to/package"

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

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


Thank you! The solution was easier than I thought. :sweat_smile: