Getting ERROR: LoadError: UndefVarError: Environment not defined when I try to use the modules I created

I am creating a module (Cows) that calls another module I created in another file (Environment), but everytime I try to use it get this message:

WARNING: replacing module Envs.
WARNING: replacing module Cows.
**ERROR:** LoadError: UndefVarError: Environment not defined
Stacktrace:
[1] top-level scope
@ ~/path/to/file/Cows.jl:9
[2] **include(** fname::String **)**
@ Base.MainInclude ./client.jl:444
[3] top-level scope
@ REPL[1]:1
in expression starting at /path/to/file/Cows.jl:7

My code is:
Cow.jl:

include("Environment.jl")

using .Envs

module Cows

mutable struct Cow
    environment::Environment
end
end

Environment.jl:

module Envs
mutable struct Environment
    distance_from_pasture::Real
    trips_milking_parlor::Integer
    topography::String
end
end

I’m using macOS Monterey 12.0.1 with a M1 processor
My Julia version is v"1.6.4"

Could someone help me? I already verified another posts here, on the forum, but I still couldn’t find a solution.

Judicious use of import, using and export

(the include makes no difference, it is just text subsitution)


module Environment
    export Env
    mutable struct Env
        distance_from_pasture::Real
        trips_milking_parlor::Integer
        topography::String
    end
end

using .Environment
export Env

module Cows
    import ..Env
    export Cow
    mutable struct Cow
        environment::Env
    end
end

using .Cows
export Cow

e = Env(1, 1, "")
c = Cow(e)
1 Like

Thank you very much! It worked!

And thanks for asking.
I didn’t know how to do most of that before you posted.

“That’s a good question, how do we do that? It’s clearly possible.”