Distributed is in stdlib, but preventing precompilation via being missing?

This will be something really stupid I’m sure. I am having trouble loading Distributed within a package that is being developed, but having no problem when using it in the project from the REPL

$ julia --project

... Version 1.10.9 (2025-03-10)

julia> using Distributed

julia> addprocs(2)
2-element Vector{Int64}:
 2
 3

julia> x = @sync @distributed (+) for i in 1:1e9
              (i * 3) / (i ^ 3)
              end
4.9348021723201505

However, if I create a module:

(benchmarks) pkg> generate TestMod
  Generating  project TestMod:
    TestMod/Project.toml
    TestMod/src/TestMod.jl

Add the following into TestMod/src/TestMod.jl

module TestMod

export mod_function

using Distributed

function mod_function()
	addprocs(2)
	x = @sync @distributed (+) for i in 1:1e9
    	(i * 3) / (i ^ 3)
	end
end

end # module TestMod

and then run via a julia REPL in my project:

$ julia --project

(benchmarks) pkg> dev TestMod/
   Resolving package versions...
    Updating `~/.../benchmarks/Project.toml`
  [981f2250] + TestMod v0.1.0 `TestMod`
    Updating `~/.../benchmarks/Manifest.toml`
  [981f2250] + TestMod v0.1.0 `TestMod`

julia> using TestMod
Info Given TestMod was explicitly requested, output will be shown live 
ERROR: LoadError: ArgumentError: Package TestMod does not have Distributed in its dependencies:
- You may have a partially installed environment. Try `Pkg.instantiate()`
  to ensure all packages in the environment are installed.
- Or, if you have TestMod checked out for development and have
  added Distributed as a dependency but haven't updated your primary
  environment's manifest file, try `Pkg.resolve()`.
- Otherwise you may need to report an issue with TestMod
Stacktrace:
 [1] macro expansion
   @ ./loading.jl:1846 [inlined]
 [2] macro expansion
   @ ./lock.jl:267 [inlined]
 [3] __require(into::Module, mod::Symbol)
   @ Base ./loading.jl:1823
 [4] #invoke_in_world#3
   @ ./essentials.jl:926 [inlined]
 [5] invoke_in_world
   @ ./essentials.jl:923 [inlined]
 [6] require(into::Module, mod::Symbol)
   @ Base ./loading.jl:1816
 [7] include
   @ ./Base.jl:495 [inlined]
 [8] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::Nothing)
   @ Base ./loading.jl:2292
 [9] top-level scope
   @ stdin:4
in expression starting at ~/.../benchmarks/TestMod/src/TestMod.jl:1
in expression starting at stdin:4
  ✗ TestMod
Precompiling TestMod finished.
  0 dependencies successfully precompiled in 2 seconds

ERROR: The following 1 direct dependency failed to precompile:

TestMod 

Failed to precompile TestMod [981f2250-5a9f-4a63-be36-82e31b8b2c23] to "~/.julia/compiled/v1.10/TestMod/jl_Uu3jVN".
ERROR: LoadError: ArgumentError: Package TestMod does not have Distributed in its dependencies:
- You may have a partially installed environment. Try `Pkg.instantiate()`
  to ensure all packages in the environment are installed.
- Or, if you have TestMod checked out for development and have
  added Distributed as a dependency but haven't updated your primary
  environment's manifest file, try `Pkg.resolve()`.
- Otherwise you may need to report an issue with TestMod
Stacktrace:
 [1] macro expansion
   @ ./loading.jl:1846 [inlined]
 [2] macro expansion
   @ ./lock.jl:267 [inlined]
 [3] __require(into::Module, mod::Symbol)
   @ Base ./loading.jl:1823
 [4] #invoke_in_world#3
   @ ./essentials.jl:926 [inlined]
 [5] invoke_in_world
   @ ./essentials.jl:923 [inlined]
 [6] require(into::Module, mod::Symbol)
   @ Base ./loading.jl:1816
 [7] include
   @ ./Base.jl:495 [inlined]
 [8] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::Nothing)
   @ Base ./loading.jl:2292
 [9] top-level scope
   @ stdin:4
in expression starting at ~/.../benchmarks/TestMod/src/TestMod.jl:1
in expression starting at stdin:

Am I being a bit dumb? Distributed is part of the standard library so why does it not load when contained within a module and instead suggest it should be installed? It could be I’m tired and not thinking straight, but regardless of it being a slightly weird thing to do, to wrap up distribution like this, surely it should be possible?

stdlibs still need to be added to a package’s environment/Project.toml. It’s not a problem running interactively in the REPL because of the way Julia stacks environments, but that global environment isn’t available inside of the module.

So you need to ]add Distributed from within the TestMod environment.

Thanks @palday that makes a bit more sense, I’ll dig into that stacking of environments. Much appreciated.