# Precompilation fails on a simple package

**URL:** <https://discourse.julialang.org/t/precompilation-fails-on-a-simple-package/65423>\
**Category:** New to Julia\
**Tags:** question, package\
**Created:** [July 28, 2021, 9:02am UTC](https://discourse.julialang.org/t/precompilation-fails-on-a-simple-package/65423 "2021-07-28T09:02:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vettert](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vettert/32/30599_2.png) [@vettert](https://discourse.julialang.org/u/vettert)\
**Post date:** [July 28, 2021, 9:02am UTC](https://discourse.julialang.org/t/precompilation-fails-on-a-simple-package/65423/1 "2021-07-28T09:02:37Z")

</div>

Hi there,  
just trying to get my first package going, so apologies if this is a newbie question 🙂

I have created a package (“] generate”) called MWE with the following content and have added DiffEqBase and ForwardDiff as packages in the local Project.toml (content of that file below).

MWE.jl content (located in MWE/src)

```julia
module MWE

using DiffEqBase
using ForwardDiff

struct Data{chunksize}
    a::DiffEqBase.DiffCache{Array{Float64,1},Array{ForwardDiff.Dual{nothing,Float64,chunksize},1}}
    b::Float64
end

end # module

```

Content of Project.toml (located in folder MWE):

```julia
name = "MWE"
uuid = "c31797ed-9657-413b-8bac-66075bf8aeb3"
authors = ["username"]
version = "0.1.0"

[deps]
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"

```

When I am trying to use this simple package (with the local environment activated), I get an error telling me that DiffCache is not defined, as below:

```julia
julia> using MWE
[Info: Precompiling MWE [c31797ed-9657-413b-8bac-66075bf8aeb3]
ERROR: LoadError: UndefVarError: DiffCache not defined
Stacktrace:
 [1] getproperty(x::Module, f::Symbol)
   @ Base .\Base.jl:26
 [2] top-level scope
   @ ~\[folders cut]\MWE\src\MWE.jl:6
 [3] include
   @ .\Base.jl:386 [inlined]
 [4] 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, UInt64}}, source::Nothing)
   @ Base .\loading.jl:1213
 [5] top-level scope
   @ none:1
 [6] eval
   @ .\boot.jl:360 [inlined]
 [7] eval(x::Expr)
   @ Base.MainInclude .\client.jl:446
 [8] top-level scope
   @ none:1
in expression starting at [... etc].

```

I tried using DiffEqBase: DiffCache at the top of MWE.jl as well (and of course altering the a:: line accordingly), but it also doesn’t work.

Can anyone help? Seems like a really basic problem that is probably caused by me doing something wrong in terms of package management…but what?

When I am c&p-ing the module code into the REPL, it’s working fine.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [July 28, 2021, 9:17am UTC](https://discourse.julialang.org/t/precompilation-fails-on-a-simple-package/65423/2 "2021-07-28T09:17:13Z")

</div>

Welcome, and thank you for the detailed MWE! I can confirm that I see the same behavior. What julia verison are you on (`versioninfo()`)? Which versions of `DiffEqBase` and `ForwardDiff` are installed (`]st`)?

This probably has to do with the use of Requires.jl in `DiffEqBase`, since that struct is requiring `ForwardDiff`. I had hoped simply swapping the `using` statements would have worked, but seems like this isn’t the case. Probably best to open an issue at `DiffEqBase`.

---

<div class="post-metadata">

**Author:** ![vettert](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vettert/32/30599_2.png) [@vettert](https://discourse.julialang.org/u/vettert)\
**Post date:** [July 28, 2021, 9:20am UTC](https://discourse.julialang.org/t/precompilation-fails-on-a-simple-package/65423/3 "2021-07-28T09:20:00Z")

</div>

Thanks for the quick reply. Already good that somebody else is able to reproduce it! 🙂  
Here is the data:

versioninfo():

```julia
Julia Version 1.6.0
Commit f9720dc2eb (2021-03-24 12:55 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i5-8365U CPU @ 1.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)

```

]status:

```julia
Project MWE v0.1.0
      Status `[...systempath...]\MWE\Project.toml`
  [2b5f629d] DiffEqBase v6.70.0
  [f6369f11] ForwardDiff v0.10.18

```

I’ll file an issue with DiffEqBase (as soon as I have reminded myself on how to do it!)

---

<div class="post-metadata">

**Author:** ![vettert](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vettert/32/30599_2.png) [@vettert](https://discourse.julialang.org/u/vettert)\
**Post date:** [July 28, 2021, 9:39am UTC](https://discourse.julialang.org/t/precompilation-fails-on-a-simple-package/65423/4 "2021-07-28T09:39:32Z")

</div>

For completeness, link to the DiffEqBase issue: [https://github.com/SciML/DiffEqBase.jl/issues/687](https://github.com/SciML/DiffEqBase.jl/issues/687)

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 31, 2021, 12:23am UTC](https://discourse.julialang.org/t/precompilation-fails-on-a-simple-package/65423/5 "2021-07-31T00:23:03Z")

</div>

This is fixed by using [GitHub - SciML/PreallocationTools.jl: Speed at all costs](https://github.com/SciML/PreallocationTools.jl) (which will be registered in 3 days)

---

<div class="post-metadata">

**Author:** ![vettert](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vettert/32/30599_2.png) [@vettert](https://discourse.julialang.org/u/vettert)\
**Post date:** [August 9, 2021, 3:29am UTC](https://discourse.julialang.org/t/precompilation-fails-on-a-simple-package/65423/6 "2021-08-09T03:29:09Z")

</div>

Thanks for this. Works out well.
