# Update a const defined in a module

**URL:** <https://discourse.julialang.org/t/update-a-const-defined-in-a-module/135548>\
**Category:** General Usage\
**Tags:** question, module\
**Created:** [February 10, 2026, 12:51am UTC](https://discourse.julialang.org/t/update-a-const-defined-in-a-module/135548 "2026-02-10T00:51:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Post date:** [February 10, 2026, 12:51am UTC](https://discourse.julialang.org/t/update-a-const-defined-in-a-module/135548/1 "2026-02-10T00:51:34Z")

</div>

Now we can update a const

```julia-auto
julia> const m = 0
0

julia> const m = 1
1

```

in a REPL.

But in a larger project I may want to wrap all the consts in another module `M`.

```julia-auto
# Opening a new julia REPL
julia> module M
           const m = 0
       end;

julia> import .M: m

julia> m
0

julia> module M # redefine
           const m = 1
       end;

julia> import .M: m # update
WARNING: ignoring conflicting import of M.m into Main

julia> m # update fails
0

```

.  
I wonder if the `m` should be updated after the second execution of `import .M:m`?

**PS** I know that I can use `M.m` directly, but that’s anything but convenient—that’s not the desired style of usage.

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [February 10, 2026, 2:34am UTC](https://discourse.julialang.org/t/update-a-const-defined-in-a-module/135548/2 "2026-02-10T02:34:12Z")

</div>

> [@WalterMadelim](#):
>
> But in a larger project I may want to wrap all the consts in another module `M`

In a larger project, the recommended workflow is to create a package and use Revise.jl. It works really well, and should (among other benefits) speed up your execution over `include`-based workfows. `using M.m` should work fine and be updated automatically if `M` is a package.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [February 10, 2026, 6:18am UTC](https://discourse.julialang.org/t/update-a-const-defined-in-a-module/135548/3 "2026-02-10T06:18:58Z")

</div>

Import statements aren’t assignments and currently cannot replace a previously imported variable. When you redefined `module M`, which is actually a `const` reassignment for the variable `M`, you threw away the only convenient reference to the old module which you could have reassigned `m`: `@eval M const m = 1`. As mentioned, Revise makes these reassignments easier for packages and `includet` files by processing source code changes. If you’re evaluating everything by hand in the REPL so Revise isn’t applicable, you can still save some typing by `REPL.activate(M)` entering the [module M in the REPL](https://docs.julialang.org/en/v1/stdlib/REPL/#Changing-the-contextual-module-which-is-active-at-the-REPL) and typing the direct line `const m = 1`.

It would be interesting if redefining modules _could_ change the old module’s variables’ imports into other modules as part of world age, even without manual reimports, but that’s a much more difficult problem. For example, what happens to `Main.m` if we had instead redefined `M` where `M.m` is not assigned?

```julia-auto
module M
  const n = 1
end

```

Does `Main.m` become undefined? Do Revise’s extra reevaluations attempt to evaluate things with the undefined `Main.m`, which errors? Should we even introduce undefining of variables like this? As far as I know, no language that allows dynamic redefinition/reloading of modules firmly specifies answers, but in practice, reloading modules risk a mixed state between the old and new modules, so it’s heavily discouraged compared to other dynamic global data.

---

<div class="post-metadata">

**Author:** ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Post date:** [February 14, 2026, 7:58am UTC](https://discourse.julialang.org/t/update-a-const-defined-in-a-module/135548/4 "2026-02-14T07:58:22Z")

</div>

I had these warnings every time.

```julia-auto
❯ julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.12.5 (2026-02-09)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org release
|__/ |

julia> import Random, JuMP

julia> Random.seed!(hash(50))
Random.TaskLocalRNG()

julia> import Pkg, Revise

julia> Pkg.activate("EM")
  Activating project at `~/cems/texworks/cems13/EM`

julia> using EM
Info Given EM was explicitly requested, output will be shown live 
┌ Warning: Module JuMP with build ID fafbfcfd-a7cd-70ee-b656-ce8a47bd8b3d is missing from the cache.
│ This may mean JuMP [4076af6c-e467-56ae-b986-b466b2749572] does not support precompilation but is imported by a module that does.
└ @ Base loading.jl:2641
  ? JuMP
  ? EM
[Info: Precompiling EM [dd2b80ec-7e5f-4d2f-a2dd-434f86dd1972] (cache misses: wrong dep version loaded (2))
┌ Warning: Module JuMP with build ID fafbfcfd-a7cd-70ee-b656-ce8a47bd8b3d is missing from the cache.
│ This may mean JuMP [4076af6c-e467-56ae-b986-b466b2749572] does not support precompilation but is imported by a module that does.
└ @ Base loading.jl:2641
┌ Info: Skipping precompilation due to precompilable error. Importing EM [dd2b80ec-7e5f-4d2f-a2dd-434f86dd1972].
└ exception = Error when precompiling module, potentially caused by a __precompile__ (false) declaration in the module.
Info Given Gurobi was explicitly requested, output will be shown live 
┌ Warning: Module MathOptInterface with build ID fafbfcfd-ecc6-dab2-1e48-bf33002016d5 is missing from the cache.
│ This may mean MathOptInterface [b8f27783-ece8-5eb3-8dc8-9495eed66fee] does not support precompilation but is imported by a module that does.
└ @ Base loading.jl:2641
  ? Gurobi
[Info: Precompiling Gurobi [2e9cd046-0924-5485-92f1-d5272153d98b] (cache misses: wrong dep version loaded (2), wrong source (2), incompatible header (10))
┌ Warning: Module MathOptInterface with build ID fafbfcfd-ecc6-dab2-1e48-bf33002016d5 is missing from the cache.
│ This may mean MathOptInterface [b8f27783-ece8-5eb3-8dc8-9495eed66fee] does not support precompilation but is imported by a module that does.
└ @ Base loading.jl:2641
┌ Info: Skipping precompilation due to precompilable error. Importing Gurobi [2e9cd046-0924-5485-92f1-d5272153d98b].
└ exception = Error when precompiling module, potentially caused by a __precompile__ (false) declaration in the module.

```

What do they mean?

Edit: Maybe due to that I’ve mixed two environments.
