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

**URL:** <https://discourse.julialang.org/t/getting-error-loaderror-undefvarerror-environment-not-defined-when-i-try-to-use-the-modules-i-created/75559>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [February 1, 2022, 6:10am UTC](https://discourse.julialang.org/t/getting-error-loaderror-undefvarerror-environment-not-defined-when-i-try-to-use-the-modules-i-created/75559 "2022-02-01T06:10:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![the\_dude](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/the_dude/32/33355_2.png) [@the\_dude](https://discourse.julialang.org/u/the_dude)\
**Post date:** [February 1, 2022, 6:10am UTC](https://discourse.julialang.org/t/getting-error-loaderror-undefvarerror-environment-not-defined-when-i-try-to-use-the-modules-i-created/75559/1 "2022-02-01T06:10:56Z")

</div>

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:

```julia
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** :

```julia
include("Environment.jl")

using .Envs

module Cows

mutable struct Cow
    environment::Environment
end
end

```

**Environment.jl** :

```julia
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.

---

<div class="post-metadata">

**Author:** ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)\
**Post date:** [February 1, 2022, 8:10am UTC](https://discourse.julialang.org/t/getting-error-loaderror-undefvarerror-environment-not-defined-when-i-try-to-use-the-modules-i-created/75559/2 "2022-02-01T08:10:12Z")

</div>

Judicious use of import, using and export

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

```julia

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)

```

---

<div class="post-metadata">

**Author:** ![the\_dude](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/the_dude/32/33355_2.png) [@the\_dude](https://discourse.julialang.org/u/the_dude)\
**Post date:** [February 18, 2022, 2:59am UTC](https://discourse.julialang.org/t/getting-error-loaderror-undefvarerror-environment-not-defined-when-i-try-to-use-the-modules-i-created/75559/3 "2022-02-18T02:59:35Z")

</div>

Thank you very much! It worked!

---

<div class="post-metadata">

**Author:** ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)\
**Post date:** [February 18, 2022, 6:17am UTC](https://discourse.julialang.org/t/getting-error-loaderror-undefvarerror-environment-not-defined-when-i-try-to-use-the-modules-i-created/75559/4 "2022-02-18T06:17:46Z")

</div>

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.”
